How do I add modules to the Eclipse Oxygen module

2019-02-19 01:35发布

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条回答
成全新的幸福
2楼-- · 2019-02-19 02:09

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.

查看更多
登录 后发表回答