Eclipse : manually select main class for executable jar file

29,485

Solution 1

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.

Solution 2

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

Share:
29,485
hqt
Author by

hqt

Those who don't speak math are doomed to speak nonsense. My brief profile: https://github.com/hqt/profile

Updated on February 01, 2020

Comments

  • hqt
    hqt about 4 years

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

  • Lucas Baizer
    Lucas Baizer almost 9 years
    I do this for a Runnable jar file, but my main class doesn't appear in the launch config,
  • CodeFactory.DEV
    CodeFactory.DEV over 8 years
    @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
  • Andrew
    Andrew over 6 years
    Run => Run Configurations... => Click configuration => Main => Main class