开发者

Get manifest-file from executed JAR

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"


OK, here is proper question:

I have main.jar with main-method (lets s开发者_开发知识库ay 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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜