I have java project, and many class that have main method (just for testing purpose). When I create executable jar file by Eclipse, Eclipse will automatically selects which file is main class. (and often wrong).
There is another way is change main class in manifest file in Jar file. But, it's so handy. So, my question is : how to choose this manually when create Jar file.
Thanks :)
We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …] As we can see, in this case, we'll have to include the main class name in the command line, followed by arguments.
In the Main tab, make sure that the "Main class:" is set to quickstart. Main . Eclipse should have identified this for you; if not, click Search... and select the class. Next, select the "Arguments" tab.
From the Eclipse IDE menu, select Search>Java ... . In the dialog, enter: "main" as the search string.
Eclipse will set the class you tell it to set. The wizard has a button for doing this.
Menus:
Or if you instead create a "Runnable JAR"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With