Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java 11 classpath only not working compared to Maven

Migrating an old ERP system to JPMS turned out to be highly problematic (Java 11 Eclipse finds automatic module, Maven does not), so I decided to first try and simply replace Java 8 with Java 11, but keep everything on the classpath by not introducing any module-info.java files. That actually went quite smoothly; Maven is compiling this without problems, and the resulting application also starts from the command line.

But when I import that Maven project into Eclipse 2019-03 it complains about a.o. java.xml packages, for example this import:

import javax.xml.namespace.QName;

This makes sense, because the JRE is modularized, and those classes are in the java.xml module which I am not included. But why is Maven then compiling correctly AND the application starting under J11?

I suspect I need to tell Eclipse to "--add-modules=ALL-SYSTEM" for this project, but I'm not sure where or how. I've tried moving all the JDK/JRE modules in the build-path/libraries from implicit to explicit, but that does not help.

like image 732
tbeernot Avatar asked Apr 03 '19 07:04

tbeernot


Video Answer


2 Answers

You probably have some redundant xml api jars on the classpath and javac (incorrectly) doesn't complain because of JDK-8215739, but Eclipse already (correctly) does after bug 536928

At runtime, the JVM seems to ignore packages on the classpath that already appear in a named module, so javac's behaviour is actually consistent with that.

To fix your problem: Try "Open Type" to find any copies of javax.xml.namespace.QName in jars on your classpath and exclude those dependencies in your pom.xml

like image 73
Till Brychcy Avatar answered Oct 29 '22 00:10

Till Brychcy


"Try "Open Type" to find any copies of javax.xml.namespace.QName in jars on your classpath and exclude those dependencies in your pom.xml" This was also the solution for my problem.In my case, I had to exclude "org.apache.axis" from axis and add a separated dependency for javax.xml.rpc

<dependency>
            <groupId>axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
          <exclusions>
                <exclusion>
                    <groupId>axis</groupId>
                    <artifactId>axis-wsdl4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.axis</groupId>
                    <artifactId>axis-jaxrpc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.xml.rpc</groupId>
            <artifactId>javax.xml.rpc-api</artifactId>
            <version>1.1.2</version>
        </dependency>
like image 24
D.Raluca Avatar answered Oct 29 '22 01:10

D.Raluca