Knowing the classpath from a jar

J

John

Hello,

When i start my application from a command line like:

java -jar myjar.jar

the system property "java.class.path" only contain "myjar.jar". But in
the jar manifest i have a line like:

Class-Path: lib1.jar lib2.jar

Is it possible to have this list easily ? If the only way is to
uncompress the jar and parse the manifest file, it does not worth it
since it's just for bug reports.

TIA
 
T

Thomas Fritsch

John said:
When i start my application from a command line like:

java -jar myjar.jar

the system property "java.class.path" only contain "myjar.jar". But in
the jar manifest i have a line like:

Class-Path: lib1.jar lib2.jar

Is it possible to have this list easily ? If the only way is to
uncompress the jar and parse the manifest file, it does not worth it
since it's just for bug reports.
You can do it with the API of package java.util.jar:
JarFile jarFile = new JarFile("myjar.jar");
String s =
jarFile.getManifest().getMainAttributes().getValue("Class-Path");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,039
Members
48,768
Latest member
first4landlord

Latest Threads

Top