简体   繁体   English

java-jar文件不直接在Windows中运行,而是通过命令提示符运行

[英]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.

相关问题 java-如何在Windows命令行中运行JAR文件,该命令行的运行时参数包含“&lt;”和“&gt;”字符 - java- how to run JAR file in Windows command line which has run time arguments containing “<” and “>” chars 在没有命令提示符的情况下在Windows上运行JAVA 8 jar - Run JAVA 8 jar on windows without command prompt Java Jar 文件主类在从命令行运行时运行,而不是从 Windows 批处理文件运行 - Java Jar file main class run when runs from command line, but not from Windows batch file 在Windows命令提示符下运行Java文件 - run java file in windows command prompt 我的Java程序在netbeans中运行,但不会在命令中或通过jar文件运行。 我究竟做错了什么? - My java program runs in netbeans, but will not run in command or through the jar file. What am I doing wrong? 爪哇视窗。 为什么我可以在命令提示符下运行 jar 文件但不能双击它 - Java Windows. why can I run a jar file on command prompt but not double clicking it 在 Windows 中使用命令提示符编译带有 Jar 依赖项的 Java 文件 - Compiling Java file with Jar dependencies using command prompt in windows 如何在Java命令提示符下运行签名的jar文件? - how to run the signed jar file in java command prompt? 如何在windows中通过命令提示符运行从selenium IDE导出的java文件 - How to run java file exported from selenium IDE through command prompt in windows Java Selenium在没有IDE的情况下通过命令提示符CMD Windows运行 - Java Selenium Run through Command Prompt CMD Windows Without IDE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM