Java jar - 没有主要清单属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31373445/
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
Java jar - no main manifest attribute
提问by patricio2626
I'm aware that jar files should have a manifest.mf Main-Class:attribute in order to have an entry point and make the jar file runnable. Now, I have a jar file that I've built per below. The classes are all part of the burrito package. My MANIFEST.MF file looks like:
我知道 jar 文件应该有一个 manifest.mf Main-Class:属性,以便有一个入口点并使 jar 文件可运行。现在,我有一个我在下面构建的 jar 文件。这些类都是 burrito 包的一部分。我的 MANIFEST.MF 文件如下所示:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.1
Created-By: 1.7.0_51-b13 (Oracle Corporation)
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
Main-Class: burrito.Main
, and when I try to build and execute via the following:
,当我尝试通过以下方式构建和执行时:
jar -cvf Burrito.jar Customer.class Main.class Server
.class Store.class MANIFEST.MF
*added manifest
adding: Customer.class(in = 2800) (out= 1424)(deflated 49%)
adding: Main.class(in = 1147) (out= 757)(deflated 34%)
adding: Server.class(in = 3954) (out= 2094)(deflated 47%)
adding: Store.class(in = 3950) (out= 2190)(deflated 44%)
adding: MANIFEST.MF(in = 203) (out= 158)(deflated 22%)*
I get:
我得到:
Burrito.jar
*java -jar Burrito.jar
no main manifest attribute, in Burrito.jar*
I've tried various ways, also trying the -m switch (cvfm). I've attempted the following:
我尝试了各种方法,还尝试了 -m 开关(cvfm)。我尝试了以下操作:
java -cp Burrito.jar burrito.Main
as well as
也
java -cp Burrito.jar Main
, which both tell me Error: Could not find or load main class
,这两个都告诉我错误:找不到或加载主类
I've been poring over forums, and I can't seem to 'Google' my way to a solution here. Of course the Netbeans jar works, but I need to build my own. I've peeked at the Netbeans jar, and I see that I have two folders, burrito and META-INF. Of course, the manifest file is in the META-INF folder, and the burrito folder contains the class files. I'm not sure exactly to mimic this, and I would be happy to simply get this program to run.
我一直在研究论坛,我似乎无法在这里“谷歌”找到解决方案。当然,Netbeans jar 可以工作,但我需要构建自己的。我偷看了 Netbeans jar,我看到我有两个文件夹,burrito 和 META-INF。当然,清单文件在 META-INF 文件夹中,而 burrito 文件夹包含类文件。我不确定要完全模仿这一点,我很乐意让这个程序运行。
Any pointers/hints?
任何指示/提示?
采纳答案by Brett Kail
You want something like this:
你想要这样的东西:
jar -cvfm Burrito.jar MANIFEST.MF burrito/Customer.class burrito/Main.class burrito/Server.class burrito/Store.class
The first argument after the options correspond to the f
flag (the file to create), and the second argument corresponds to the m
flag (the manifest file), and all the other arguments are the files to add to the JAR. You have to ensure the folder structure in the JAR matches the Java package, so if burrito.Main
is the class, then you need burrito/Main.class
in the JAR, and similarly for the other classes.
options 后的第一个参数对应于f
标志(要创建的文件),第二个参数对应于m
标志(清单文件),所有其他参数是要添加到 JAR 的文件。您必须确保 JAR 中的文件夹结构与 Java 包匹配,因此如果burrito.Main
是类,那么您需要burrito/Main.class
在 JAR 中,其他类也是如此。