从执行的 JAR 中获取清单文件
假设我有:
核心.jar
client.jar(包含主方法)(使用 core.jar)
super_mega_client.jar(使用 core.jar、client.jar)
为了运行我的程序,我使用“java -jar super_mega_client.jar”
我如何从“super_mega_client.jar”获取清单文件而不知道它的名称和内容?
实际上我需要在 core.jar 中创建一个 util,它将与 jar 一起使用,用“java -jar ***.jar”执行
好的,这是正确的问题:
我有 main.jar 和 main-method (可以说在 my.app.Main 类中)
我还有 fisrt.jar (带有一些类和资源)和 second.jar (带有一些其他类和资源)。两者都没有主类,在 CLASSPATH 中都有“main.jar”,两者的 Main-Class 属性都定义为“my.app.Main”。
我可以通过执行“java -jar first.jar”或“java -jar secondary.jar”来运行我的应用程序
在我的 my.app.Main.main(String[] args)
方法(包含在 main.jar 中)中,我想知道执行的 jar 的名称(我想获取“first.jar”或“second.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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在声明其主类的任何 jar 中,位置和名称均由标准固定为
META-INF/MANIFEST.MF
您可以使用
jar
命令检索清单文件Java SDK 附带的文件(您可以从该命令运行的任何 zip 工具也可能就足够了),方法是运行:这将创建 META-INF 目录并将清单文件放入其中。如果您想要更少的详细输出,您可以省略 -v。
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: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.
不太确定我明白你在这里需要什么,但请查看这篇文章(例如)
http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.html
您询问 CLASSLOADER (因此使用您已经加载的类并请求它使用的类加载器可能足够好)来为您加载资源。
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.
您可以使用
java
命令的-verbose
选项来查看所有加载的类的名称。You can use the
-verbose
option of thejava
command to see the names of all loaded classes.