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

故事扮演 提交于 2019-12-01 06:30:31

问题


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?


回答1:


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. 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
    
  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. 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.

  4. 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;.

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.



来源:https://stackoverflow.com/questions/44403070/how-do-i-add-modules-to-the-eclipse-oxygen-module-path-for-a-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!