英文:
Eclipse can't run java project with module warning
问题
我正在运行带有OpenJDK-14的Eclipse 4.16。我有一个简单的Java项目,其中包含一个lib文件夹,里面有一个swt.jar文件。它已经在项目的“属性” > “Java构建路径” > “库”对话框中添加到了模块路径中。当我在我的类中导入并使用一个swt类时,我被提示在我的module-info文件中添加一个条目。它添加了一个带有警告的“swt”:
自动模块的名称'swt'不稳定,它是从模块文件名派生的。
当我尝试将项目作为Java应用程序运行时,控制台会显示以下错误,并且没有任何内容运行:
初始化引导层时发生错误
java.lang.module.FindException: 未找到模块swt,ca.footeware.swt.converter所需
如果我将项目导出为带有封闭依赖项的可运行jar包,它能够运行,但会出现类似的警告。导出的jar包能够运行(但这不是方便的开发周期🙂)。
我在某个地方读到,对于非模块化的jar包,可以使用MANIFEST.MF头部Automatic-Module-Name。我打开了swt.jar并添加了带有值org.eclipse.swt的头部,该值是该jar包的根包。我从module-info.java中删除了Requires swt;,然后再次被提示从我的类中添加一个带有swt导入的条目。但这次它输入了Requires org.eclipse.swt;,并且没有产生警告。然而,当我尝试运行项目时,我收到了相同的错误:
初始化引导层时发生错误
java.lang.module.FindException: 未找到模块org.eclipse.swt,ca.footeware.swt.converter所需
英文:
I'm running eclipse 4.16 with OpenJDK-14. I have a simple java project that has a lib folder with swt.jar in it. It was added to the modulepath in the project's Properties > Java build path > Libraries dialog. When I import and use an swt class in my class, I'm prompted to add an entry to my module-info file. It adds "swt" with a warning:
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:
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. The exported jar does run (but it's not a convenient development cycle
I read somewhere that for non-modular jars a MANIFEST.MF header, Automatic-Module-Name, can be used. 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; from my module-info.java and again was prompted to add an entry from my class with an swt import. This time though it entered 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
答案1
得分: 0
我搞定了!我的运行配置的 VM 参数现在是:
--module-path ca.footeware.converter:ca.footeware.converter.temperature:/home/craig/Downloads/swt.jar -m ca.footeware.converter/ca.footeware.converter.Converter
我在 Linux 上,--module-path 的分隔符应该是冒号 :,而不是分号。
注意,我已将运行配置的工作目录设置为 ${workspace_loc},而不是默认的 ${workspace_loc:ca.footeware.converter},这样我就可以通过简单名称而不是完全限定名称访问两个模块项目,例如 /home/craig/workspace/ca.footeware.converter.temperature。
英文:
I got it working! My Run Configuration's VM args is now:
--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 ;.
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, e.g. /home/craig/workspace/ca.footeware.converter.temperature.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论