0

I have a Java program that uses XML parsing so it uses many libraries like:

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
...
import org.w3c.dom.Document;
import org.w3c.dom.Element;
...

It compiles and works when I use Java 1.8. It compiles using command line javac compiler from OpenJDK 12:

[root@mn ~]# javac --version
javac 12.0.1

[root@mn ~]# alternatives --config javac
...
*  1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.fc30.x86_64/bin/javac)
 + 2           java-latest-openjdk.x86_64 (/usr/lib/jvm/java-12-openjdk-12.0.1.12-1.rolling.fc30.x86_64/bin/javac)

But I have some problems when in Eclipse I change "Compiler compliance level" from 1.8 to 11. Then Eclipse shows a lot of errors like:

The package javax.xml.validation is accessible from more than one module: <unnamed>, java.xml
...
Element cannot be resolved to a type

My Eclipse version:

Version: 2019-03 (4.11.0)
Build id: 20190314-1200

EDIT

I updated Eclipse to:

Version: 2019-06 (4.12.0)
Build id: 20190614-1200

The error is the same. At compile time:

The package org.w3c.dom is accessible from more than one module: <unnamed>

At runtime:

Exception in thread "abc" java.lang.Error: Unresolved compilation problems:
    The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml

I can compile and run this program using command line JDK12 javac/java.

My question is different from Eclipse Java Editor highlights the error but code compiles because I can see problems in "Problems" tab and I cannot run the program from Eclipse.

What should I do to compile my program in Eclipse using Java11/12?

SOLUTION

I removed xml-apis-1.3.04.jar from my CLASSPATH and program compiles and runs from Eclipse. Thank you howlger :-)

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • 2
    You run into a [bug that has already been fixed in the current release](https://stackoverflow.com/a/55948524/6505250). [Please upgrade](https://wiki.eclipse.org/FAQ_How_do_I_upgrade_Eclipse_IDE%3F#Always_enable_major_upgrades). – howlger Jun 24 '19 at 11:52
  • I upgraded Eclipse, but my problems have not disappeared :-( See my edited question. – Michał Niklas Jun 25 '19 at 12:08
  • 1
    Then Eclipse is probably right and the `javax.xml.validation` package is contained in the module `java.xml` (as part of the system library) on the _Module Path_ and in a JAR or in a _Class Folder_ on the _Classpath_ (= the `` module): see _Project > Properties: Java Build Path: Libraries_. This is not allowed according to the Java language specification. Either do not use Java modules (by deleting the `module-info.java` file) or get rid of the dependency that is not JPMS ready because it is using the `javax.xml.validation` package which is already used in the system library. – howlger Jun 25 '19 at 13:45
  • 1
    For more details see: https://stackoverflow.com/a/55572922/6505250 – howlger Jun 25 '19 at 17:03
  • That `javac` is compiling your code is a bug and may change in future Java versions. According to the Java language specification it should be a compile error instead (like it is already in the Eclipse Java Compiler): https://stackoverflow.com/a/53824670/6505250 – howlger Jun 26 '19 at 06:57
  • OK. Thank you. I removed `xml-apis-1.3.04.jar ` from my CLASSPATH and program compiles and runs from Eclipse. Can you write an answer which I can vote :-) – Michał Niklas Jun 27 '19 at 05:40
  • 1
    Closed questions cannot be answered, but you can vote for [Stephan Herrmann's anwer which gives the root cause](https://stackoverflow.com/a/53824670/6505250) (Stephan is a developer of the Eclipse Java compiler and asked a developer of `javac` for clarification/confirmation). – howlger Jun 27 '19 at 06:31

0 Answers0