java 如何从jar文件中获取java主类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38164604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:11:03  来源:igfitidea点击:

How to get java main class from jar file

javaexecutable-jar

提问by Yaz

I have an executable jar and i want to know the name of java main classfrom this jar

我有一个可执行的 jar,我想main class从这个 jar 中知道 java 的名称

My question are if there is a java cmdto get this from jar metadata ?

我的问题是是否java cmd可以从 jar 元数据中获取此信息?

回答by sauumum

You can use unix command : unzip -p XXX.jar META-INF/MANIFEST.MF

您可以使用 unix 命令: unzip -p XXX.jar META-INF/MANIFEST.MF

or you can use jar commad jar tf XXX.jarand see the content of MANIFEST.MF.

或者您可以使用 jar 命令 jar tf XXX.jar并查看MANIFEST.MF.

回答by larsgrefer

Technically a jar file can contain more than one main class.

从技术上讲,一个 jar 文件可以包含多个主类。

When java executes a jar file, it looks in the META-INF/MANIFEST.MFfile inside the jar to find the entrypoint.

当java执行一个jar文件时,它会在META-INF/MANIFEST.MFjar内部的文件中查找入口点。

There is no direct command to get this information, but you can unpack the jar (it's just a zip file) and look into the manifest yourself.

没有直接命令来获取此信息,但您可以解压缩 jar(它只是一个 zip 文件)并自己查看清单。

More about the manifest: https://docs.oracle.com/javase/tutorial/deployment/jar/defman.html

有关清单的更多信息:https: //docs.oracle.com/javase/tutorial/deployment/jar/defman.html

More about application entrypoints: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

有关应用程序入口点的更多信息:https: //docs.oracle.com/javase/tutorial/deployment/jar/appman.html