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

前端 未结 1 741
孤城傲影
孤城傲影 2021-01-14 13:21

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

相关标签:
1条回答
  • 2021-01-14 14:11

    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.

    0 讨论(0)
提交回复
热议问题