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/.

🌐
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 ...
Discussions

Module Path Vs Class Path in eclipse | Selenium Forum
Module Path Vs Class Path in eclipse .Hello, Can you pls help me understand what is the diferences between Module Path and Class Path in eclipse ? Issue i obse 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
Missing ModulePath and ClassPath on Java, Eclipse IDE - Stack Overflow
Eclipse IDE PrintScreen As you can see in this screenshot, the ModulePath and ClassPath are missing. I am trying to solve this error: Error occurred during initialization of boot layer java.lang.m... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - A: Incrementally add a module-info.java and gradually move dependencies from classpath to modulepath. Start with core dependencies that have module support, use automatic modules for others, and plan a timeline for the full migration. This prevents breaking the entire build at once. Q: Why does Eclipse show "Unbound classpath container" errors?
🌐
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
On the Libraries tab, click Add Variable for adding a variable that refers to a JAR file. 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...
🌐
Eclipse
help.eclipse.org › latest › topic › org.eclipse.jdt.doc.user › reference › ref-properties-build-path.htm
Java Build Path
Adding a required project indirectly adds all its classpath entries marked as 'exported'. Setting a classpath entry as exported is done in the Order and Export tab.
🌐
Techwalla
techwalla.com › tech support › how to
How to Set the Classpath in Eclipse | Techwalla
February 9, 2017 - ... Right click on the name of the project that you want to build a classpath for in the Package Explorer bar. Click "Build Path" and then choose "Configure Build Path...". ... Click "Add Folder..." to add the source that you want to build the ...
🌐
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.
Find elsewhere
🌐
CodingTechRoom
codingtechroom.com › question › eclipse-modulepath-vs-classpath
Understanding the Difference Between Modulepath and Classpath in Eclipse - CodingTechRoom
// For modulepath: // Right click on project > Build Path > Configure Build Path > Libraries > Add Module Path... The classpath is used for traditional Java applications to locate classes and resources at runtime. The modulepath is a feature introduced with Java 9 that supports the Java Platform ...
🌐
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.


🌐
Eclipse
bugs.eclipse.org › bugs › show_bug.cgi
520300 – [9] Nodes for module path and class path on Java Build Path
September 29, 2017 - Download · Getting Started · Members · Projects · Community · Marketplace · Events · Planet Eclipse · Videos · Participate
🌐
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
🌐
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.
🌐
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 ...
🌐
Stack Overflow
stackoverflow.com › questions › 76596575 › missing-modulepath-and-classpath-on-java-eclipse-ide
Missing ModulePath and ClassPath on Java, Eclipse IDE - Stack Overflow
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.
🌐
Eclipse Foundation
eclipse.org › community › eclipse_newsletter › 2018 › june › java9andbeyond.php
Embracing Java 9 and beyond with Eclipse JDT | The Eclipse Foundation
Eclipse IDE provides a quick fix in module-info.java to import class and add requires to module-info.java. If a buildpath entry specified in Classpath is used in module-info.java, the Eclipse IDE will suggest moving of the classpath entry to modulepath.
🌐
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.
🌐
Learn IT University
learn-it-university.com › home › understanding eclipse build paths: modulepath vs classpath explained
Understanding Eclipse Build Paths: Modulepath vs Classpath Explained - Learn IT University
June 21, 2024 - Moving your test dependencies to the classpath for effective compilation within Eclipse Photon ensures smoother project development and testing procedures. Understanding the nuances of working with the classpath and modulepath in Eclipse facilitates efficient project structuring and management particularly in adopting the Java 9 and newer runtime environments for enhanced modularity and dependency management.
🌐
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.
🌐
Apache
db.apache.org › derby › docs › 10.17 › getstart › tgs26250.html
Manually setting the CLASSPATH/MODULEPATH environment variables
You can set the CLASSPATH and MODULEPATH environment variables in the operating system either temporarily, permanently, or at run time when you start your Java application and the JVM.