Java jar - 没有主要的清单属性 [英] Java jar - no main manifest attribute

查看:150
本文介绍了Java jar - 没有主要的清单属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道jar文件应该有一个manifest.mf Main-Class:属性,以便有一个入口点并使jar文件可以运行。现在,我有一个jar文件,我已经在下面构建了。这些课程都是墨西哥卷饼套餐的一部分。我的MANIFEST.MF文件如下所示:

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:

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%)*

我得到:

Burrito.jar

*java -jar Burrito.jar
no main manifest attribute, in Burrito.jar*

我尝试了各种方法,也尝试了-m开关(cvfm)。我尝试过以下方法:

I've tried various ways, also trying the -m switch (cvfm). I've attempted the following:

java -cp Burrito.jar burrito.Main

以及

java -cp Burrito.jar Main

,它们都告诉我错误:无法找到或加载主类

我一直在研究论坛,而我似乎无法通过'谷歌'找到解决方案。当然,Netbeans jar工作,但我需要建立自己的jar。我偷看了Netbeans jar,我看到我有两个文件夹,burrito和META-INF。当然,清单文件位于META-INF文件夹中,而burrito文件夹包含类文件。我不确定是否完全模仿这个,我很乐意简单地让这个程序运行。

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.

任何指针/提示?

推荐答案

你想要这样的东西:

jar -cvfm Burrito.jar MANIFEST.MF burrito/Customer.class burrito/Main.class burrito/Server.class burrito/Store.class

选项后的第一个参数对应 f flag(要创建的文件),第二个参数对应 m 标志(清单文件),所有其他参数都是文件添加到JAR。您必须确保JAR中的文件夹结构与Java包匹配,因此如果 burrito.Main 是该类,则需要 burrito / Main。在JAR中有类,对于其他类也是如此。

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.

这篇关于Java jar - 没有主要的清单属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆