The difference between classpath and modemlepath when importing jar package in eclipse

First of all, when importing the jar package, it must be imported into the classpath.
If it is imported into the moduelpath, an error will occur when importing the interface (the interface cannot be found)

The difference between classpath and modulepath:
The concept of ModulePath is similar to ClassPath, but the Jar package or Jmod file in ModulePath is treated as a Module, and the Jar package in ClassPath is treated as a traditional Jar package regardless of whether it is modular or not.

Java9 has established the following rules to ensure that old Jar packages and projects can be seamlessly migrated to the new Java version:

All Jar packages, Classes, resource files, etc. under ClassPath are in an Unnamed Module
Class of Unnamed Module. You can see and use all the packages exported in the Module Path, all the
packages in the Class Path, and all the JDK system module Package ModulePath The Class in the ordinary module can only see the Package exported from the dependent module defined in module-info, and can not see the content in the Unnamed Module.
According to these rules, if the project still uses ClassPath, it has no impact on the project, and the project does not need to define module dependencies. In addition, the project's dependencies can be placed on ClassPath or ModulePath. The difference is that packages placed on ModulePath cannot be used in packages not marked as exported.

Need to explain Unnamed Module here. Unnamed Module is a special, automatically generated Module. All contents under ClassPath are hung under Unnamed Module name in Java9. For the same ClassLoader, there is only one Unnamed Module.

Published 9 original articles · Likes0 · Visits 797

Guess you like

Origin blog.csdn.net/Tao_Yuanqiang/article/details/102573993