简体   繁体   English

Eclipse 无法运行 java 项目并出现模块警告

[英]Eclipse can't run java project with module warning

I'm running eclipse 4.16 with OpenJDK-14.我正在使用 OpenJDK-14 运行 eclipse 4.16。 I have a simple java project that has a lib folder with swt.jar in it.我有一个简单的 java 项目,其中有一个包含 swt.jar 的 lib 文件夹。 It was added to the modulepath in the project's Properties > Java build path > Libraries dialog.它被添加到项目的 Properties > Java build path > Libraries 对话框中的模块路径中。 When I import and use an swt class in my class, I'm prompted to add an entry to my module-info file.当我在 class 中导入和使用 swt class 时,系统会提示我向我的模块信息文件添加一个条目。 It adds "swt" with a warning:它添加了带有警告的“swt”:

Name of automatic module 'swt' is unstable, it is derived from the module's file name.

When I try to run the project as a java application I get this error in console and nothing runs:当我尝试将项目作为 java 应用程序运行时,我在控制台中收到此错误并且没有运行:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module swt not found, required by ca.footeware.swt.converter

If I export the project as a runnable jar with dependencies enclosed, it works with a similar warning.如果我将项目导出为可运行的 jar 并附带依赖项,则它会出现类似的警告。 The exported jar does run (but it's not a convenient development cycle:)导出的 jar 确实可以运行(但这不是一个方便的开发周期:)

I read somewhere that for non-modular jars a MANIFEST.MF header, Automatic-Module-Name, can be used.我在某处读到,对于非模块化 jars,可以使用 MANIFEST.MF header,自动模块名称。 I cracked open the swt.jar and added the header with value org.eclipse.swt, the root package of the jar. I cracked open the swt.jar and added the header with value org.eclipse.swt, the root package of the jar. I removed the Requires swt;我删除了 Requires swt; from my module-info.java and again was prompted to add an entry from my class with an swt import.来自我的 module-info.java 并再次被提示从我的 class 中添加一个带有 swt 导入的条目。 This time though it entered Requires org.eclipse.swt;这次虽然进入 Requires org.eclipse.swt; and no warning was produced.并且没有产生警告。 When I tried running the project however I got the same error:当我尝试运行该项目时,我得到了同样的错误:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.eclipse.swt not found, required by ca.footeware.swt.converter

I got it working: My Run Configuration's VM args is now:我得到了它的工作:我的运行配置的 VM args 现在是:

--module-path ca.footeware.converter:ca.footeware.converter.temperature:/home/craig/Downloads/swt.jar -m ca.footeware.converter/ca.footeware.converter.Converter

I'm on linux and the --module-path separator should be:, not;.我在 linux 上,--module-path 分隔符应该是:,不是;。

Note I've set the Run Configuration's Working Directory to ${workspace_loc} rather than the default ${workspace_loc:ca.footeware.converter} so that I could access both module projects by simple name rather than fully qualified name, eg /home/craig/workspace/ca.footeware.converter.temperature.注意我已经将运行配置的工作目录设置为 ${workspace_loc} 而不是默认的 ${workspace_loc:ca.footeware.converter} 以便我可以通过简单名称而不是完全限定名称来访问两个模块项目,例如 /home/克雷格/工作区/ca.footeware.converter.temperature。

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

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