tags:

views:

258

answers:

5

Let's say I have:
core.jar
client.jar (contains main-method) (uses core.jar)
super_mega_client.jar (uses core.jar, client.jar)

To run my program I use "java -jar super_mega_client.jar"
How could I get the manifest-file from "super_mega_client.jar" knowing nothing about it's name and content?
Actualy I need to create an util in core.jar which will work with the jar, executed with "java -jar *.jar"

+1  A: 

See this question.

er4z0r
I know neither jar-name, no any class name. I only know that jar was used in "java -jar *.jar" command.
Chris Rea
+1. Using the answer cited, you can search the manifest of each potential JAR, e.g. `find /path/to/jars -name '*jar' | xargs manifest`
trashgod
A: 

In any jar that declares its main class, the location and name is fixed by the standard to META-INF/MANIFEST.MF

You can retrieve the manifest file using the jar command that comes with the Java SDK (any zip tool that you can run from the command might suffice too) by running:

jar -xvf anyjar.jar META-INF/MANIFEST.MF

this will create the META-INF directory and put the manifest file in it. You can leave out the -v if you want less verbose output.

rsp
A: 

Not quite sure I understand what you need here, but check out this article (for instance)

http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.html

You ask the CLASSLOADER (so use a class you have loaded already and request what classloader it used is probably good enough) to load the resource for you.

monojohnny
A: 

You can use the -verbose option of the java command to see the names of all loaded classes.

trashgod
A: 

OK, here is proper question:
I have main.jar with main-method (lets say in my.app.Main class)
I also have fisrt.jar(with some classes and resources) and second.jar (with some other classes and resources). Both have no main-classes, both have "main.jar" in CLASSPATH, both have Main-Class property defined as "my.app.Main".
I can run my app by executing "java -jar first.jar" or "java -jar second.jar"
In my my.app.Main.main(String[] args) method (contained in main.jar) I want to know the name of the executed jar (I want to get either "first.jar" or "second.jar")
How could I do it?

Chris Rea