How java finds entry point in multiple jars specified with -classpath option

936 Views Asked by At

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.

  1. How does JAVA find, where to start, which class file has main?
  2. also If two jars in classpath have menifest file, specifying Main-Class, what happens ?
1

There are 1 best solutions below

0
On

Once you check documentation to CLI java you will see there are only two options:

java [ options ] class [ arguments ]

here you specify the class you want to execute.. or

java [ options ] -jar file.jar [ arguments ]

you specify exactly one JAR file which (as you already know) must contain Main-Class in manifest.