且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-09-19 19:26:28

这就是我的工作方式(前几步是针对那些尚未为JDK 9设置Eclipse的用户):

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):

  1. 安装JDK 9(此时Oracle可提供9.0.1).
  2. 通过添加以下行并修改eclipse.ini并重新启动Eclipse,将Eclipse配置为与JDK 9一起运行:

  1. Install JDK 9 (9.0.1 was available at this time from Oracle).
  2. Configure Eclipse to run with JDK 9 by modifying eclipse.ini by adding these lines and restart Eclipse:

-vm
<fullPathToJDK9>/bin
--add-modules=ALL-SYSTEM

  • 在项目属性中,转到"Java Build Path",然后在"Classpath"下,为要成为模块的每个jar展开扭曲.您应该看到一个名为不是模块化"的新条目.单击它,然后单击编辑"按钮.在打开的模块化属性"对话框下,选中定义一个或多个模块"框.单击确定",它现在应该显示是模块化",它将被移至模块路径".

  • 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. You should see a new entry called "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". Click OK and it should now say "Is modular" and it will be moved up to Modulepath.

    应用所做的更改,您的module-info.java应该能够要求这些jar.使用不带任何版本标识符或.jar后缀的jar名称,例如对于myLib-1.0.jar,请使用requires myLib;.

    Apply your changes and your module-info.java should be able to require those jars. Use the name of the jar without any version identifier or .jar suffix, e.g. for myLib-1.0.jar, use requires myLib;.

    顺便说一句,我遇到了Maven生成的名称为appName-1.0-SNAPSHOT.jar之类的jar的问题.我无法在module-info.java中使用它们,因为找不到它.摆脱SNAPSHOT部件后,便可以使用它了.

    By the way, I had a problem with Maven generated jars with names like appName-1.0-SNAPSHOT.jar. I could not use them in module-info.java because it couldn't find it. Getting rid of the SNAPSHOT part made it possible to use it.