[英]java- jar file does not run directly in windows, but runs through command prompt
I am trying to run a desktop java app on a Windows 2008 Server based PC. 我试图在基于Windows 2008 Server的PC上运行桌面java应用程序。
While I can run the program through command prompt viz. 虽然我可以通过命令提示符运行该程序。 java -jar filename.jar, when I double click on the jar file I get an error message "Could not find the main class. Program will now exit".
java -jar filename.jar,当我双击jar文件时,我收到一条错误消息“无法找到主类。程序现在将退出”。
I am using Netbeans v7.0.1 on Windows, to develop this application. 我在Windows上使用Netbeans v7.0.1来开发此应用程序。 Kindly clarify on how to run the app directly on double clicking its icon...
请详细说明如何在双击其图标时直接运行应用程序...
You need to set the Main-class in the Manifest.txt file 您需要在Manifest.txt文件中设置Main-class
Main-Class: MyPackage.MyClass
This sets the entry point for the application. 这将设置应用程序的入口点。
Check out the documentation for more details, 查看文档以获取更多详细信息,
http://download.oracle.com/javase/tutorial/deployment/jar/appman.html http://download.oracle.com/javase/tutorial/deployment/jar/appman.html
Since you're using Netbeans, you need to edit the manifest.mf
file in the META-INF
folder in your .jar archive to point to your MAIN
class. 由于您使用的是Netbeans,因此需要编辑.jar存档中
META-INF
文件夹中的manifest.mf
文件以指向您的MAIN
类。
If your .jar file is myjar.jar
, open it up, then open the manifest.mf
file and edit the Main-Class
line to point to your main class (the one that contains your main method). 如果你的.jar文件是
myjar.jar
,打开它,然后打开manifest.mf
文件并编辑Main-Class
行指向你的主类(包含你的main方法的那个)。
Main-Class: mainclass.myjar
Save it and run. 保存并运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.