Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running java [-options] -jar jarfile (no explicit classname given)

Tags:

java

jar

Please correct me if I am wrong.

When running java [-options] -jar jarfile with no explicit class name, if a single class exists within the jar that contains a public static void main(String[] args) method, that method will be invoked automatically. Right?

What happens if I have several classes that contain an eligible main method?

like image 387
Yaneeve Avatar asked May 29 '26 08:05

Yaneeve


2 Answers

It uses the Main-Class defined in the MANIFEST file to determine which class contains the main method that should be run.

see http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

like image 107
digitaljoel Avatar answered May 31 '26 23:05

digitaljoel


The class to run is taken from the Manifest metadata.

Main-Class :

The value of this attribute defines the relative path of the main application class which the launcher will load at startup time. The value must not have the .class extension appended to the class name.

like image 42
Thomas Jung Avatar answered May 31 '26 22:05

Thomas Jung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!