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