Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse : manually select main class for executable jar file

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

like image 988
hqt Avatar asked Oct 10 '12 03:10

hqt


People also ask

How do I run a specific main class in a JAR file?

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.

How do I set main class in Eclipse?

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.

How do I find the main class in Eclipse?

From the Eclipse IDE menu, select Search>Java ... . In the dialog, enter: "main" as the search string.


1 Answers

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.
like image 114
Hovercraft Full Of Eels Avatar answered Nov 05 '22 03:11

Hovercraft Full Of Eels