如何将模块添加到项目的Eclipse Oxygen模块路径? [英] How do I add modules to the Eclipse Oxygen module path for a project?

查看:201
本文介绍了如何将模块添加到项目的Eclipse Oxygen模块路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,今天有几个罐子作为参考库".相反,我想将这些作为自动模块添加到模块路径中,以便可以在我的module-info.java中要求它们.您如何在Eclipse Oxygen中将jar添加到模块路径?

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. How do you add jars to the module path in Eclipse Oxygen?

推荐答案

这就是我的工作方式(前几步是针对那些尚未为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.

    这篇关于如何将模块添加到项目的Eclipse Oxygen模块路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆