我创建了一个程序,它或多或少地将一组字符串作为对象并随机打印一个。
所以基本上
class Fun
{
string[] namestrings = new string[#]
constructor()
{ fill with some strings}
public static void main (String[]arg)
{
create instance of class
do some junk with it
method that prints it
}
method that prints it {}
another method
}
当我在命令行上编译并运行它时,它工作正常,但是在命令行上我输入 jar -cf Happy.jar Fun.class
我得到一个名为 Happy 的 .jar 文件,当我单击它时,我收到一条错误消息,上面写着“java Jar 文件 happy 无法启动,请阅读控制台以获取可能的错误消息” 我正在运行一台 mac豹,如果这有什么不同的话。这是怎么回事?
最佳答案
有一个包含以下内容的manifest.mf,并将其打包到您的JAR文件中作为META-INF/manifest.mf
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.3-b01 (Sun Microsystems Inc.)
Main-Class: Fun
然后您可以使用以下命令执行您的应用程序
java -jar Happy.jar
如果您将项目创建为 Java 应用程序,IDE 通常会自动为您执行此操作。
关于java - 我的 .jar 文件不会执行任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2680432/