Eclipse Java 11 classpath only not working compared to Maven
Asked Answered
R

3

6

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.

Roshelle answered 3/4, 2019 at 7:55 Comment(5)
I also encountered this error, it occurs since Eclipse 2019-03, the previous Eclipse releases did not show this error.Livestock
I have the same issue under Eclipse 2018-12, what previous version did you use?Roshelle
What maven plugins (and versions) are you using?Reinsure
Eclipse is a complete vanilla install, maven is 3.5.3 using the 3.7.0 version of the compiler plugin.Roshelle
java.xml is a part of java.se module so it should work out of the box. No special command line options should be needed. It's strange that you have such an error in Eclipse. I don't see anything like that (I have Eclipse 2018-12).Pryer
N
6

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

Nomenclator answered 4/4, 2019 at 7:16 Comment(5)
Interesting. Yes, I was able to remove the QName message is this way. Now I moved the JRE to the bottom of the classpath, so I can find duplicates by jumping to the first jar that holds it, and also confirm that thet are in the JRE. But I still have errors for w3c classes (e.g. Document) which do not seem to be duplicate, but Eclipse still think they are: The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xmlRoshelle
If you see that only in the editor, but not in the problems view, this is probably bug bugs.eclipse.org/bugs/show_bug.cgi?id=545687. In this case, please try with a 4.12 integration build from download.eclipse.org/eclipse/downloadsNomenclator
No, it also is in the problems view.Roshelle
If you really don't have any other type in that package on the classpath, you found another bug. In case you can extract a reproducible test case, please create a bug report at bug bugs.eclipse.orgNomenclator
Eclipse was indeed correctly indicating a problem which javac did not detect yet (JDK-8215739)Roshelle
S
1

"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>
Sepal answered 16/11, 2021 at 13:21 Comment(0)
P
0

for any poor souls still working with axis 1.3, the group id you need to exclude is just axis

    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.3</version>
        <exclusions>
            <exclusion>
                <groupId>axis</groupId>
                <artifactId>axis-wsdl4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>axis</groupId>
                <artifactId>axis-jaxrpc</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Preshrunk answered 29/1, 2022 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.