This is been troubling me for a long time.
In Linux, I see a process cmdLine is like below :
/usr/java/jdk1.7.0_65/bin/java-Dsosa-Djava.security.policy=conf/sosa.policy-Dlog4j.configuration=properties/sosa-log4j.properties-Xms256m-Xmx1024m-classpath:/opt/HP/jboss/standalone/deployments/hpsa.ear/lib/sosa.jar:/opt/HP/jboss/standalone/deployments/hpsa.ear/lib/mwfm.jar
I understand:
-D : we specify property
-classpath : we specify the path to be searched
Question: During JVM instance creation, how does java finds the main class or entry points if we have multiple jars/ears in the -classpath option.
I understand, We can specify the main class in MANIFEST file like :Main-Class: MyPackage.MyClass
But I see above jars does't have Main-Class entry in MANIFEST file.
- How does JAVA find, where to start, which class file has main?
- also If two jars in classpath have menifest file, specifying Main-Class, what happens ?
Once you check documentation to CLI java you will see there are only two options:
here you specify the class you want to execute.. or
you specify exactly one JAR file which (as you already know) must contain
Main-Class
in manifest.