我的 .jar 文件无法在 java 中运行
我已经创建了一个应用程序,当我通过 NETBEANS 执行它时它工作正常。
之后,我单击“清理并构建”来构建 SiteScrapper.jar 文件。现在,当我通过命令提示符调用以下 dos 命令来执行它时:
java -jar "SiteScrapper.jar"
我收到以下异常
sitescrapper.Main class not found
我的主类位于以下包中
com.innoConsulting.sitescrapper
I have created an application and it is working correctly when I am executing it through NETBEANS.
After that I had clicked on "Clean and Build" to build a SiteScrapper.jar file. Now when I am executing it through command prompt by invoking the following dos command:
java -jar "SiteScrapper.jar"
I am getting the following exception
sitescrapper.Main class not found
My Main class is located in the following package
com.innoConsulting.sitescrapper
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要检查Manifest文件中
Main-Class
的值。You need to check the value of
Main-Class
in the Manifest file.您的 JAR 需要 META-INF/manifest.mf 说明主类所在位置的文件。
Your JAR needs a META-INF/manifest.mf file that spells out where the main class is.
您需要包含一个清单文件。请参阅此处以获取快速说明: http://www.skylit.com/javamethods/faqs /createjar.html
You need to include a manifest file. See here for a quick explanation: http://www.skylit.com/javamethods/faqs/createjar.html
在 Netbeans 中,要么运行项目(它会要求您提供主类),要么进入项目 |属性 |运行并选择主类。
然后进行另一次清理和构建,它将生成带有适当清单文件(带有 Main-Class: set)的 JAR 文件。
In Netbeans either run the project (and it will ask you for the Main-Class) or go into the Project | Properties | Run and select the Main-Class.
Then do another clean and build and it will generate the JAR file with the appropriate manifest file (with the Main-Class: set).
确保 jar 文件是“可执行的”。 Manifest 需要具有 Main-Class 属性。
Make sure that the jar file is 'executable'. The Manifest needs to have the Main-Class attribute.