I'm trying to migrate some legacy applications to the new Java 9 module system, to strengthen its encapsulation.
I'm starting from the outside-in, with the assumption that classes on the periphery will have the least external dependencies.
As you'd expect, I've declared a very open module to start with:
module com.example.user {
exports com.example.user;
}
This instantly breaks the entire project (inside all classes), when suddenly every import for an external dependency no longer resolves (causing over 1k Java problems):
The import com.otherexample cannot be resolved
The import org.springframework cannot be resolved
etc.
Local packages in the same project com.example.price
still work - as do java.util
etc.
All of the external dependencies are (were) managed with Maven. In the (Eclipse project) build path, I can still see them as "Classpath" dependencies - but only the JRE system libraries in the "Modulepath".
Can the two concepts co-exist? Currently it seems by having a single module-info.java
anywhere in the project, all classpath dependencies stop working?
I did read about using automatic modules, which seemed to imply you could use legacy / non-modular jars by including them in your modulepath, then referring to them by their filename. They use the example:
module com.foo.myapp {
requires guava; // guava not yet modularised, so use the filename
}
I couldn't find much other info, but this appears to match the convention Eclipse uses when it auto-generates a module-info.java for example:
spring-core-4.3.8.RELEASE.jar
becomes:
requires spring.core;
However, this still results in a Java error reported by Eclipse:
spring.core cannot be resolved to a module
Maven reports:
[ERROR] module-info.java:[39,16] error: module not found: spring.core
...and every class in the project with an external dependency is still broken.
Eclipse Oxygen 4.7.1a
and as well asJava9 support(BETA)
...in case you've upgraded Eclipse.. Otherwise, it would be good to see the project structure and its correspondingpom.xml
content to see why its not working. – Adhesive