简体   繁体   English

Eclipse 无法创建可运行的 jar - 未选择资源

[英]Eclipse cannot create runnable jar - No resources selected

When I try to export my project as a runnable jar Eclise gives me the following error:当我尝试将项目导出为可运行的 jar 时,Eclise 出现以下错误:

No resources selected.没有选择资源。

The project runs fine within Eclipse, I already tried to clean the project before exporting, but that didn´t work.该项目在 Eclipse 中运行良好,我已经尝试在导出之前清理该项目,但这没有用。

Any ideas on how to fix this.有想法该怎么解决这个吗。

The problem is most likely with your run configuration.问题很可能与您的运行配置有关。

  • Go to your Class that contains the main(String[] args) method you wish to automatically run when the jar is called from the command line转到包含您希望在从命令行调用 jar 时自动运行的 main(String[] args) 方法的类
  • Right-click->Run As...->Application右键单击->运行方式...->应用程序
  • Make sure it runs to your satisfaction确保它运行令您满意
  • Now go through the export process as before, selecting the newly created launch configuration.现在像以前一样完成导出过程,选择创建的启动配置。

The last step is key.最后一步是关键。

I found another solution.我找到了另一个解决方案。

I found that there's a bug in JDK 9.我发现 JDK 9 中有一个错误。

I solved it by downgrade to JDK 8(1.8.1)我通过降级到 JDK 8(1.8.1) 解决了这个问题

I fixed the problem, I exported the project as an archive file.我解决了这个问题,我将项目导出为存档文件。 Then I opened up a new workspace and imported the the archived project.然后我打开了一个新的工作区并导入了存档的项目。 After that I tried to export the project as a runnable jar, after two tries the jar runs as is it should.之后我尝试将项目导出为可运行的 jar,经过两次尝试后 jar 运行正常。

I still don't know what the exact cause was but I hope someone how has run into the same problem finds this helpful.我仍然不知道确切的原因是什么,但我希望遇到同样问题的人觉得这很有帮助。

Doing a (project->clean) and creating a new run configuration (with correct project and class name with main() method, selected) solved the problem for me.You just have to select the new run configuration while exporting runnable jar:)执行 (project->clean) 并创建一个新的运行配置(使用 main() 方法选择正确的项目和类名)解决了我的问题。您只需在导出可运行的 jar 时选择新的运行配置:)

Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included试试这个,这是在 eclipse 中创建 jar 或 runnable jar 的方法,项目中的所有外部库都将被包含

File -> Export-> Java ->Runnbale JAR file

Launch configuration : your Class containing the public static void main(String[] args)

Export destination : Target place

Library Handling:

Package required libraries into generated JAR

FINISH

When you click this option in Eclipse you should get a popup that lets you choose what files to export, you need to select the src folder.当您在 Eclipse 中单击此选项时,您应该会看到一个弹出窗口,让您选择要导出的文件,您需要选择 src 文件夹。

I was having this same problem, and I was able to resolve it.我遇到了同样的问题,我能够解决它。 Maybe you should cross verify the main class, that you selected in this project.也许你应该交叉验证你在这个项目中选择的main类。 It is possible that some other project's main class may have the same name as the main class you selected.其他项目的main类可能与您选择的main类同名。 Make sure the main class you selected is the one from the project that you selected.确保您选择的main类是您选择的项目中的类。

The problem is your package.问题是你的包裹。 You probably renamed it, and in the export option, the program was confused, and it was using the first name of your package.您可能重命名了它,并且在导出选项中,程序被混淆了,它使用了您的包的名字。

This is basically happen when you change package name under which you made your program.当您更改程序包名称时,这基本上会发生。 This will create confusion regarding package, as per program export, main method still written in old package.这会造成包的混乱,根据程序导出,主要方法仍然写在旧包中。 To resolve it, Just copy it and paste it in same package with different name and then try to export it.要解决它,只需将其复制并粘贴到具有不同名称的同一包中,然后尝试将其导出。 Check for log too.也检查日志。

I was in the same situation.我处于同样的情况。 For me deleting existing eclipse installation(not not the project workspace) and opening the existing eclipse workspace with new installation of eclipse was the only thing that worked.对我来说,删除现有的 eclipse 安装(不是项目工作区)并使用新安装的 eclipse 打开现有的 eclipse 工作区是唯一有效的方法。

Just copy the project as a new one.只需将项目复制为一个新项目即可。 Configure the build path by creating new Run/Debug Settings.this would resolve the problem.通过创建新的运行/调试设置来配置构建路径。这将解决问题。

I continued to get the "no resources selected" error.我继续收到“未选择资源”错误。 I then did the procedure I am quoting and it gave me a MANIFEST file.然后我执行了我引用的程序,它给了我一个 MANIFEST 文件。 Then I was able to create an executable JAR.然后我能够创建一个可执行的 JAR。

Quoting: "I exported the project as an archive file. Then I opened up a new workspace and imported the the archived project. After that I tried to export the project as a runnable jar, after two tries the jar runs as is it should."引用:“我将项目导出为存档文件。然后我打开了一个新的工作区并导入了存档的项目。之后我尝试将项目导出为可运行的 jar,经过两次尝试后 jar 运行正常。 “

I also faced the same issue, in my case, I just closed the project and reopened it, now it's wokring我也遇到了同样的问题,就我而言,我只是关闭了项目并重新打开它,现在它正在工作

Check that your project is correct at the time when you select the main class.在选择主类时检查你的项目是否正确。

If the class non exist, it's the standard error of Eclipse.如果该类不存在,这是 Eclipse 的标准错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM