Eclipse Fails to Load XML Classes After Switching to JDK 10
When migrating a Maven project to JDK 10, Eclipse developers may encounter an issue where XML-related classes become inaccessible during compilation. This error only occurs within the Eclipse build environment, while Maven builds and individual class browsing remain unaffected.
Cause:
The source of this problem lies in the unnamed module utilized by the project, which lacks a module-info.java. This implies that code is compiled within the unnamed module, which reads observable named and unnamed modules, including java.xml. However, the classpath also contains xml-apis.java, contributing conflicting packages of the same names.
Resolution:
To resolve this issue, two options are available:
1. Create a module-info.java file:
Add a module-info.java file to your project and specify which modules are required:
requires ...*;
Replace ... with either java.xml or xml.apis.
2. Limit Observable Modules in Eclipse:
In Eclipse, navigate to Java Build Path > Libraries > Classpath and open the "Modularity Details" dialog. Exclude java.xml from the set of observable modules by moving it from the "Explicitly Included Modules" to the "Available Modules" section. Any modules essential to your project can be selectively added back.
Additional Information:
The above is the detailed content of Why Can\'t Eclipse Load XML Classes After JDK 10 Migration?. For more information, please follow other related articles on the PHP Chinese website!