The module system has mainly the following impact on the code:

  • A package can only be accessed from one module (Nested packages are treated as separate, so even though the package java.util is in the module java.base, the package java.util.logging can be in the module java.logging)
  • You can only access public fields and methods of code in exported packages of other modules. This is true even with reflection (i.e. java.lang.reflect.AccessibleObject.setAccessible(boolean) only works for code in the same module)

All code that is on the classpath lives together in the "unnamed" module. All code on the modulepath lives in their own "named" modules.

You have to distinguish two cases:

  • If you don't add a module-info.java to your project, your project will be part of the unnamed module and can see all other code in the unnamed module, plus code in java.base and code in modules in java.se root module. Basically this means that w.r.t. code on the classpath, everything still works as in Java 8, so you should just put your dependencies on the classpath.

  • If you have a module-info.java in your project, your project will be in its own named module and can only see code in java.base and other named modules which are references using "requires"-clauses in the module-info.java. As named modules are only found via the module path, you should put your dependencies on the module path. This even works for jars created before Java 9, which will get a module name derived from the .jar file name (in which case they are called "automatic" module).

The JRE is always on the module-path, so that its internal code cannot be accessed even from code on the classpath.

There is one special case: If you have a module-info.java in your project and have test code in your project, you usually don't want to mention test dependencies like junit in the module-info.java. There are two solutions for this:

  • Create a dedicated test module. This has always been the convention for osgi-based projects. Disadvantage is that you can only use public API in your tests

  • The solution used by Maven: Put your test dependencies on the classpath. When compiling test code, Maven adds command line options that allow the code in the named module to read the unnamed module (which is not possible via the module-info.java).

In Eclipse Oxygen, the Maven solution was not possible, because it has no notion which code is test code, but this has been implemented in the upcoming Eclipse Photon (4.8) release, which will be out in June. You can already work with the (feature-complete) milestone builds from http://download.eclipse.org/eclipse/downloads/. In case you find any bugs, please report them at https://bugs.eclipse.org/bugs/.

Answer from Till Brychcy on Stack Overflow
Top answer
1 of 1
46

The module system has mainly the following impact on the code:

  • A package can only be accessed from one module (Nested packages are treated as separate, so even though the package java.util is in the module java.base, the package java.util.logging can be in the module java.logging)
  • You can only access public fields and methods of code in exported packages of other modules. This is true even with reflection (i.e. java.lang.reflect.AccessibleObject.setAccessible(boolean) only works for code in the same module)

All code that is on the classpath lives together in the "unnamed" module. All code on the modulepath lives in their own "named" modules.

You have to distinguish two cases:

  • If you don't add a module-info.java to your project, your project will be part of the unnamed module and can see all other code in the unnamed module, plus code in java.base and code in modules in java.se root module. Basically this means that w.r.t. code on the classpath, everything still works as in Java 8, so you should just put your dependencies on the classpath.

  • If you have a module-info.java in your project, your project will be in its own named module and can only see code in java.base and other named modules which are references using "requires"-clauses in the module-info.java. As named modules are only found via the module path, you should put your dependencies on the module path. This even works for jars created before Java 9, which will get a module name derived from the .jar file name (in which case they are called "automatic" module).

The JRE is always on the module-path, so that its internal code cannot be accessed even from code on the classpath.

There is one special case: If you have a module-info.java in your project and have test code in your project, you usually don't want to mention test dependencies like junit in the module-info.java. There are two solutions for this:

  • Create a dedicated test module. This has always been the convention for osgi-based projects. Disadvantage is that you can only use public API in your tests

  • The solution used by Maven: Put your test dependencies on the classpath. When compiling test code, Maven adds command line options that allow the code in the named module to read the unnamed module (which is not possible via the module-info.java).

In Eclipse Oxygen, the Maven solution was not possible, because it has no notion which code is test code, but this has been implemented in the upcoming Eclipse Photon (4.8) release, which will be out in June. You can already work with the (feature-complete) milestone builds from http://download.eclipse.org/eclipse/downloads/. In case you find any bugs, please report them at https://bugs.eclipse.org/bugs/.

🌐
Eclipse
help.eclipse.org › latest › topic › org.eclipse.jdt.doc.user › reference › ref-properties-build-path.htm
Java Build Path
Setting a classpath entry as exported is done in the Order and Export tab. The projects selected here are automatically added to the referenced projects list. The referenced project list is used to determine the build order. A project is always build after all its referenced projects are built.
Discussions

How in Eclipse project module java-9 have modulepath and classpath together?
Hello, For my first contact with Gradle I created a java module project (OpenJDK-11) under Eclipse. The version of Eclipse is “2019-09 (4.13)” and I used the plugin “Buildship Gradle integration 3.0” to create the project. I ended up figuring out how to set up the build.gradle file ... More on discuss.gradle.org
🌐 discuss.gradle.org
0
0
October 1, 2019
Module Path Vs Class Path in eclipse | Selenium Forum
Reference: https://stackoverflow.com/questions/50321602/in-eclipse-what-is-the-difference-between-modulepath-and-classpath/50324391 ... not sure whether i clearly understand the details mentioned in the stackoverflow. Is it possible o explain with an example ? ... A ClassPath is a sequence of classes and packages (or JARs) which are user-defined classes and built-in classes. JVM or Java ... More on qtpselenium.com
🌐 qtpselenium.com
Understanding the Module Path, Class Path, and Eclipse
I found the redundant jar by using Ctrl Shift T to open the type editor and the searching on that name. More on reddit.com
🌐 r/javahelp
1
1
December 26, 2019
Eclipse: Add dependencies to the module path
Eclipse: Oxygen Buildship: 2.2.0 Gradle: 4.3.1 In Eclipse, when using java8, gradle dependencies are automatically added to the classpath (by Buildship, I believe). When using java 9 Eclipse define... More on github.com
🌐 github.com
6
December 11, 2017
🌐
Eclipse
archive.eclipse.org › eclipse › downloads › documentation › 2.0 › html › plugins › org.eclipse.jdt.doc.user › tasks › tasks-114.htm
Adding a classpath variable to the build path
The New Variable Classpath Entry dialog appears which shows all available classpath variables. You can Edit... New... a variable or create a new variable with New.... Press New... Enter the variable's name and path then press OK. If the variable resolves to a folder, you have to specify a path extension that points to a JAR. To do this press the Extend... button. If the variable already resolves to a JAR file you can click OK directly. Hint: You can add multiple variable entries at once to the Java build path: Select more than one variable in the New Variable Classpath Entry dialog, or multiple JAR files in the Variable Extension dialog.
🌐
CopyProgramming
copyprogramming.com › howto › module-path-and-classpath-in-eclipse
Module Path and Classpath in Eclipse: Complete 2026 Guide - Module path and classpath in eclipse complete
November 15, 2025 - When you run mvn clean install, Eclipse's m2e integration automatically synchronizes your build path settings, creating the correct classpath/modulepath configuration without manual intervention. For Gradle with Buildship integration, the build path is automatically configured from your build.gradle or build.gradle.kts file. Use the java and java-library plugins appropriately.
🌐
Gradle
discuss.gradle.org › help/discuss › buildship
How in Eclipse project module java-9 have modulepath and classpath together? - Buildship - Gradle Forums
October 1, 2019 - Hello, For my first contact with Gradle I created a java module project (OpenJDK-11) under Eclipse. The version of Eclipse is “2019-09 (4.13)” and I used the plugin “Buildship Gradle integration 3.0” to create the project. I ended up figuring out how to set up the build.gradle file ...
🌐
qtpselenium
qtpselenium.com › selenium-training › forum › module-path-vs-class-path-in-eclipse-4485
Module Path Vs Class Path in eclipse | Selenium Forum
Can you pls help me understand what is the diferences between Module Path and Class Path in eclipse ? ... I was trying to launch browser thorugh webdriver, i copied all Selenium jars in module path, but the code was failing with error NoClassDefFound then i cpoied all jars in class path and now i am able to launch the browser. Can you pls help me understand why this happened ? ... All code that is on the classpath lives together in the "unnamed" module. All code on the modulepath lives in their own "named" modules.
🌐
Techwalla
techwalla.com › tech support › how to
How to Set the Classpath in Eclipse | Techwalla
February 9, 2017 - The exact library you may need varies with your project. For example, to add the Java runtime environment, choose "JRE System Library" and click "Next." ... Click "Finish" to complete setting up the path for the JRE system library.
Find elsewhere
🌐
Reddit
reddit.com › r/javahelp › understanding the module path, class path, and eclipse
r/javahelp on Reddit: Understanding the Module Path, Class Path, and Eclipse
December 26, 2019 -

I've been helping to migrate a large Java 8 project ( 100s of plugins/projects integrated as one SWT application to Java 11 ( version Version: 2019-06 (4.12.0) ).

I've been getting Eclipse error messages along the lines of

The package foo is accessible from more than one module: <unnamed>, foo

Googling around I learned that these situations always existed, but Eclipse hasn't reported them until now. It seem to be the root of the problem is that Java improved. If you make a "Hello World" program into an executable, you don't need to bundle all of the java libraries with it, only the modules you need. So now there is a module path. If you have a library listed in the module path AND the class path you get the kind of errors I did.

That is my superficial understanding, I'm looking for a deeper one.

Does the module path make the classpath obsolete in an application?

Are there tools for Eclipse to tell you were a conflicting library is located ( or a missing library )?

What is the best practice for resolving these conflicts? Removing the redundant entry from the classpath or module path?

The tiny bit of knowledge I got was from Stackoverflow. If there is a doc that explains it in more depth please point me to it. Bonus points if it explains the mechanics of it "like I am 5"


Edit:

I found the redundant jar by using Ctrl Shift T to open the type editor and the searching on that name.


🌐
CodingTechRoom
codingtechroom.com › question › eclipse-modulepath-vs-classpath
Understanding the Difference Between Modulepath and Classpath in Eclipse - CodingTechRoom
Learn about the differences between modulepath and classpath in Eclipse and how to use them effectively to manage JAR files.
🌐
GitHub
github.com › eclipse › buildship › issues › 620
Eclipse: Add dependencies to the module path · Issue #620 · eclipse-buildship/buildship
December 11, 2017 - When using java 9 Eclipse defines a module path in addition to the classpath. This is visible in the project configuration Java Build Path / Libraries page.
Author   eclipse-buildship
🌐
Baeldung
baeldung.com › home › java › core java › classpath vs. modulepath in java
Classpath vs. Modulepath in Java | Baeldung
January 16, 2024 - We include the lib/mylibrary.jar file in the classpath using the -cp option and the current directory (.) where the program’s class files reside. It is a collection of directories, JAR files, and modules that contain compiled module files ...
🌐
www.java4coding.com
java4coding.com › contents › java › java9features › classpath-vs-modulepath
Classpath Vs Modulepath - java4coding
Will be applicable to all java versions. Will be applicable to java version 9 and above.Classpath does not require module-info.java module-info.java is necessary for modulepath. Adding libraries to classpath works only if project does not have module-info.java file.
🌐
Apache
db.apache.org › derby › docs › 10.15 › getstart › tgs26250.html
Manually setting the CLASSPATH/MODULEPATH environment variables
Use the setEmbeddedCP script to set CLASSPATH and MODULEPATH when the database engine is used in embedded mode.
🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 1108820
Eclipse Community Forums: Newcomers » Eclipse IDE for Java Developers 2021-06 Cannot find class paths | The Eclipse Foundation
September 1, 2021 - The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
🌐
IBM
ibm.com › docs › en › spm › 7.0.9
Configuring the Eclipse classpath variables and the Elipse ...
May 11, 2021 - In Eclipse, you must set the classpath variables and configure the Eclipse Tomcat Plugin.
🌐
ConcretePage
concretepage.com › questions › 640
CLASSPATH vs MODULEPATH in Java
December 11, 2018 - CLASSPATH is the location of user defined classes or packages. ... Link for MODULEPATH example. https://www.concretepage.com/java/java-9/java-module
🌐
Stack Overflow
stackoverflow.com › questions › 76596575 › missing-modulepath-and-classpath-on-java-eclipse-ide
Missing ModulePath and ClassPath on Java, Eclipse IDE - Stack Overflow
That clearly does not work. ... Right click on the project Run As > Run Configurations > dependencies there you will see classpath. ... Sign up to request clarification or add additional context in comments.