简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM