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?
-
Did you try using `javac --module-path mods --module-source-path "./*/src/main/java" --add-modules ALL-MODULE-PATH -d classes -module initial.module `? Follow this -> http://jigsaw-dev.1059479.n5.nabble.com/Combining-add-modules-ALL-MODULE-PATH-with-module-source-path-td5715171.html – Naman Jun 07 '17 at 04:57
-
@nullpointer I don't quite see how this is related to an Eclipse setup. Are you saying that everything related to modules should go in the "Run Configurations"? – tibbe Jun 07 '17 at 05:03
-
Have you installed the Beta of the Java 9 Support? – greg-449 Jun 07 '17 at 06:37
-
@greg-449 yes I have. – tibbe Jun 07 '17 at 11:30
-
2With latest builds you can mark an ordinary "Referenced Library" as an automatic module, see the `Build Path > Libraries` properties page, find a child node "Module:", which you can `Toggle` between "Yes" and "No". If you still have problems, please tell us your exact version of the Eclipse JDT patch, since these things are still work in progress. – Stephan Herrmann Aug 04 '17 at 09:10
-
@Stephan Hermann. I have: – juerg Sep 30 '17 at 14:19
-
@Stephan Hermann. I have: 1.1.1.v20170826-0521_BETA_JAVA9 and 1.1.1.v20170826-0521_BETA_JAVA9 as source patch for Oxygen. Reading your comment I tried to toggle the Module:No entry, on junit.jar and on org.hamcrest.core_1.3.0v...jar. No chance, nothing toggles. And of course junit is not seen as automatic module. – juerg Sep 30 '17 at 14:27
-
@juerg, much has happened still after 20170826, so I suggest to either pick up Oxygen.1 plus the patch version corresponding to Java 9 GA (should be >= 20170921) _or_ wait until the release of Oxygen.1a scheduled for Oct. 11, by which Eclipse will bring Java 9 support natively, i.e. without the need for a patch feature. – Stephan Herrmann Oct 03 '17 at 18:09
1 Answers
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):
- Install JDK 9 (9.0.1 was available at this time from Oracle).
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.

- 47,830
- 31
- 106
- 135

- 859
- 8
- 21
-
moving a project from IntelliJ to Eclipse -- these steps got me running – saqe hi Feb 06 '18 at 09:04