Issue
I have two main classes. One for my GUI and one for my server program in the same project for an assignment.
Currently in the project config, the main class is set to my GUI main class.
I built the project to get the .jar executable file in /dist of the project folder. When I execute the .jar file, the GUI comes up but the functionalities do no work as the results needed are to be provided by the server program.
Is there a way on Netbeans to build the project so that when I execute the .jar file, both the GUI and server are executed? Or do I have to create a separate java project for the server program?
(Don't want to do the latter part)
Solution
You can't have two main methods (or at least two selected main methods) in one jar file. Think about it, how would java know which one to run when executing the file?
I don't know the setup of your project exactly or what its doing, so I can't really tell you if making the server a separate program is better or not, but you most likely don't need to do that.
Just move the contents of the server's main method into the GUI main method and it should work fine. If you are calling static methods, then just create an instance of the server if you don't have one already (which you should anyways if you are going this route).
Again I don't know the specifics of your project, but post some code and I can try to help you out some more.
Answered By - BeyondPerception