这些正是创建可执行jar文件所需的步骤,以便我可以通过双击运行我的swing程序,但它给我一个错误,说“无效或损坏的jar文件” 还试图通过命令提示符执行它给我同样的错误
Step 1:create a .java file which contains my swing code
Step 2:compile the .java file to .class file
Step 3:create jar file using the command jar cf name.jar classname.class
Step 4:open jar file using winrar archiever and modify manifest file by adding Main-class:classname
Step 5:try to execute the jar file
但上述步骤不起作用,我不明白为什么?
我也尝试过另一件事
Step 1:create a .java file which contains my swing code
Step 2:compile the .java file to .class file
Step 3:create jar file using the command jar cf name classname.class
Step 4:open jar file using winrar archiever and modify manifest file by adding Main-class:classname
Step 5:try to execute the jar file.In this case i can open my file through command prompt but not by double clicking. I tried to select javaw option through Open with option but it doesn't give any ouput(not even error)
答案 0 :(得分:2)
您可以尝试:
java -cp name.jar Classname
并在命令提示符处检查错误。
如果您的程序需要一些外部库,您可以在清单文件中提及它们。
Class-Path: lib/file1.jar lib/file2.jar
其中lib
与jar文件所在的目录相同。