简体   繁体   English

如何将模块添加到项目的Eclipse Oxygen模块路径中?

[英]How do I add modules to the Eclipse Oxygen module path for a project?

I have a project that today has several jars as "Referenced Libraries". 我有一个项目,今天有几个罐作为“参考图书馆”。 I'd instead like to add these as automatic modules on the module path so I can require them in my module-info.java. 我想在模块路径上添加这些作为自动模块,所以我可以在我的module-info.java中要求它们。 How do you add jars to the module path in Eclipse Oxygen? 如何在Eclipse Oxygen中将jar添加到模块路径?

Here is how I got it to work (first few steps are for those that haven't set up Eclipse for JDK 9 usage yet): 以下是我如何使用它(前几个步骤适用于尚未设置Eclipse用于JDK 9的用户):

  1. Install JDK 9 (9.0.1 was available at this time from Oracle). 安装JDK 9(目前可从Oracle获得9.0.1)。
  2. Configure Eclipse to run with JDK 9 by modifying eclipse.ini by adding these lines and restart Eclipse: 通过添加这些行来修改eclipse.ini并重新启动Eclipse,将Eclipse配置为使用JDK 9运行:

     -vm <fullPathToJDK9>/bin --add-modules=ALL-SYSTEM 
  3. In your project properties, go to Java Build Path, and under Classpath, expand the twisty for each jar that you want to be a module. 在项目属性中,转到Java Build Path,在Classpath下,展开要作为模块的每个jar的twisty。 You should see a new entry called "Is not modular". 您应该看到一个名为“Is not modular”的新条目。 Click on it and click the Edit button. 单击它,然后单击“编辑”按钮。 Under the Modular properties dialog that opens, check the box "Defines one or more modules". 在打开的Modular属性对话框下,选中“定义一个或多个模块”框。 Click OK and it should now say "Is modular" and it will be moved up to Modulepath. 单击OK,它现在应该说“Is modular”,它将被移动到Modulepath。

  4. Apply your changes and your module-info.java should be able to require those jars. 应用您的更改,您的module-info.java应该能够要求这些罐子。 Use the name of the jar without any version identifier or .jar suffix, eg for myLib-1.0.jar, use requires myLib; 使用没有任何版本标识符或.jar后缀的jar名称,例如对于myLib-1.0.jar,使用requires myLib; .

By the way, I had a problem with Maven generated jars with names like appName-1.0-SNAPSHOT.jar . 顺便说一下,我遇到了Maven生成的jar的问题,其名称类似于appName-1.0-SNAPSHOT.jar I could not use them in module-info.java because it couldn't find it. 我无法在module-info.java中使用它们,因为它无法找到它。 Getting rid of the SNAPSHOT part made it possible to use it. 摆脱SNAPSHOT部分可以使用它。

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

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