Eclipse : manually select main class for executable jar file
Asked Answered
M

3

11

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 :)

Misology answered 10/10, 2012 at 3:40 Comment(0)
G
24

Eclipse will set the class you tell it to set. The wizard has a button for doing this.
Menus:

  • Export
  • Java, JAR file
  • Next (select classes to be included)
  • Enter name and path for jar
  • Next (not finish)
  • Next
  • Browse for main class.

Or if you instead create a "Runnable JAR"

  • Export
  • Java, Runnable JAR File
  • Launch configuration -- here select your main class.
Gormley answered 10/10, 2012 at 3:42 Comment(2)
I do this for a Runnable jar file, but my main class doesn't appear in the launch config,Ambitendency
@LucasBaizer run your app at least once (right click on the main class from the project view > Run as > Run as Java Application). then try making a runnable jar again, it should showInconsistency
S
2

If you export a Runnable Jar, you can specify a launch configuration. This launch configuration can then specify an executable main class.

Sanctify answered 10/10, 2012 at 3:43 Comment(1)
Run => Run Configurations... => Click configuration => Main => Main classSuperiority
E
1

right click Main.java=>export Runnable JAR file=>Launch configuration(select YOUR CLASS)

enter image description here

enter image description here

Elroy answered 11/11, 2022 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.