10

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

hqt
  • 29,632
  • 51
  • 171
  • 250

3 Answers3

23

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.
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 1
    I do this for a Runnable jar file, but my main class doesn't appear in the launch config, – Lucas Baizer Jun 08 '15 at 00:39
  • 1
    @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 show – CodeFactory.DEV Sep 09 '15 at 03:08
2

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

Arcymag
  • 1,037
  • 1
  • 8
  • 18
1

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

enter image description here

enter image description here

LIU YUE
  • 1,593
  • 11
  • 19