Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.class.path doesn't bring Manifest.mf Class-Path property

I'm trying to get my application classpath.

I have a jar (named application.jar) and it have in its Manifest.mf other jar files, like Class-Path: a.jar b.jar.

Why when I use System.getProperty("java.class.path") my jars a.jar and b.jar are not listed?

like image 415
patricK Avatar asked Oct 06 '22 15:10

patricK


1 Answers

It possibly has to do with the fact that the java.class.path is a system property that is set from the classpath environment variable ($CLASSPATH or -classpath). These are ignored with the -jar option is used.

As per the java -jar documentation, when that jar option is used to run an application, only the manifest Class-Path is considered and other settings are ignored. From http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html:

-jar

Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests.

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

like image 151
Shyamal Pandya Avatar answered Oct 10 '22 02:10

Shyamal Pandya