78

I'm developing on a Maven project (branch platform-bom_brussels-sr7) in Eclipse. When I recently tried switching the Java Build Path for the project to JDK 10, Eclipse build can no longer find classes such as javax.xml.xpath.XPath, org.w3c.dom.Document, or org.xml.sax.SAXException. It seems only XML related classes are impacted, mostly from the Maven dependency xml-apis-1.4.01.

Trying a Maven build from Eclipse works without errors. Ctrl-LeftClick on one of the supposedly missing classes finds the class and opens it in the Eclipse editor. It seems only the Eclipse build is impacted.

I tried several things, but none helped. I tried:

  • Project Clean
  • Different Eclipse Versions: Oxygen and Photon.
  • Running Eclipse itself with JDK 8 and JDK 10.
  • Changing Compiler Compliance level for the project. It builds with compliance level 8 and 10 under JDK 8 build path and fails for both with JDK 10 in build path.
Carsten
  • 4,204
  • 4
  • 32
  • 49
  • 1
    I don't know anything about Eclipse but the classes you list are in the java.xml module. If you were previously deploying xml-apis-1.4.01 on the class path then I assume the classes were never actually loaded from that JAR file, they were loaded (and continue to be loaded) from the JDK. Does your project build/run outside of Eclipse? – Alan Bateman Jun 29 '18 at 06:35
  • Yes, a maven command line build, or even a explicit maven build within Eclipse both work. It's just the Eclipse built-in build that fails. – Carsten Jun 29 '18 at 07:16
  • You have to use Oxygen.1a or newer, the original Oxygen release simply doesn't support Jigsaw. Your best bet is to stay on Photon while you try to figure this out. As a Maven project, shouldn't you be setting compiler versions in the `pom.xml`? – nitind Jun 29 '18 at 07:37
  • @nitind pom.xml sets the compiier to 10, but you can overwrite this in the Eclipse build preferences. – Carsten Jul 01 '18 at 01:55
  • @AlanBateman are you aware of any excuse why `javac` would be allowed to accept a package that is not uniquely visible? (see also my answer). I could not find anything that would define named vs. unnamed module conflicts as being exempted from the rule. Am I missing s.t.? – Stephan Herrmann Dec 18 '18 at 00:04
  • 1
    Stephan - can you bring your question to to jigsaw-dev? – Alan Bateman Dec 18 '18 at 07:42
  • @AlanBateman, done, see http://mail.openjdk.java.net/pipermail/jigsaw-dev/2018-December/014076.html (I didn't see your reply earlier since you didn't "mention" me). – Stephan Herrmann Dec 18 '18 at 19:10
  • I am having same issue in 2021, Eclipse 2021-03, OpenJDK 11 and Oracle JDK11. I read below answer and it is great answer but I dont know how to fix it, specifically refering to Solution #3 provided by @StephanHerrmann. The answer is great but I wish there were more details, I was not able to follow with my version of Eclipse. – pixel Oct 26 '21 at 20:12

10 Answers10

114

I assume that the project being migrated from Java 1.8 still has no module-info.java. This implies you are compiling code in the "unnamed module".

Code in the unnamed module "reads" all observable named and unnamed modules, in particular it reads module "java.xml" from the JRE System Library. This module exports package like java.xml.xpath.

Additionally, you have xml-apis.java on the classpath, which contributes another set of packages of the same names (java.xml.xpath and friends). These are said to be associated to the unnamed module, like your own code.

This situation violates the requirement of "unique visibility" as defined in JLS §7.4.3 (last paragraph). In particular every qualified type name Q.Id (JSL §6.5.5.2) requires that its prefix Q is a uniquely visible package (I'm disregarding the case of nested types for simplicity). Ergo: the program is illegal and must be rejected by compilers.

This leaves us with one question and two solutions:

(1) Question: Why is javac accepting the program?

(2) Solution: If you add module-info.java to your project, you can control via requires which module your project reads, either requires java.xml; or requires xml.apis; (where "xml.apis" is the automatic module name of "xml-apis-1.4.01.jar).

(3) Solution: Short of turning your project into a module, you can still avoid the conflict by excluding java.xml from the set of observable modules. On the command line this would be done using --limit-modules. The equivalent in Eclipse is the "Modularity Details" dialog, see also the JDT 4.8 New&Noteworthy (look for Contents tab). Since java.xml is implicitly required via a lot of other default-observable modules, it may be a good idea to push everything except for java.base from right ("Explicitly included modules") to left ("Available modules") (and selectively re-add those modules that your project needs).

PS: Eclipse still doesn't provide an ideal error message, instead of "cannot be resolved" it should actually say: "The package javax.xml.xpath is accessible from more than one module: javax.xml, <unnamed>.

PPS: Also weird: how come that changing the order between JRE and a jar on the classpath (such ordering is not a concept supported by javac nor JEP 261) changes the behavior of the compiler.

EDITs:

  • Alex Buckley confirmed that the given situation is illegal, despite what javac says. Bug against javac has been raised as JDK-8215739. This bug has been acknowledged months before the release of Java 12. As of 2019-06 it has been decided that also Java 13 will ship without a fix. Similarly for Java 14. The bug was temporarily scheduled for Java 15, but this plan has been dropped on 2020-04-20.
  • Eclipse error message has been improved to mention the real problem.
  • In Eclipse 2019-06 the UI used for Solution (3) has been revamped. Up-to-date documentation can be found in the online help.
  • As of 2022-12 there's yet another perspective on this issue as described in my other answer. It doesn't invalidate what's said here, but let's things appear in a different light.
Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
  • Maybe I'm missing something, but 1) the test project I mentioned in [Bug 536928](https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928) is using the classpath, not modules, so I had understood (perhaps incorrectly) that `module-info.java` would have no relevance in a case like this; and 2) to my knowledge the test case I provided does not have `xml-apis` anywhere in the classpath, nor in transitive dependencies—unless I missed them somewhere. – Garret Wilson Dec 18 '18 at 01:19
  • @GarretWilson ad (1): since Java 9, the JRE is always modular, so the "old world" is only approximately emulated by putting all non-modular code into one or more unnamed modules. Even for unnamed modules, new rules are in effecte starting with Java 9. Adding `module-info.java` is not part of the problem, but part of the solution (thereby moving your code from classpath to modulepath). – Stephan Herrmann Dec 18 '18 at 01:36
  • @GarretWilson ad (2): different people have dropped different examples into the Eclipse bug report. The initial report had xml-apis.jar in its transitive dependencies, so that's the case being handled in that bug, and it's also the case discussed in this SO thread. If you are certain that xml-apis.jar is nowhere in the picture in your case, then you are facing a different problem - which matches to the observation that only in your case explicit vs. on-demand imports seemed to make a difference, not here, though. – Stephan Herrmann Dec 18 '18 at 01:41
  • OK; that's why I put up a bounty, to get to the bottom of it. ;) Thanks for all your hard work. I'm just looking for an answer that applies to my case as well. – Garret Wilson Dec 18 '18 at 01:48
  • this bounty is expiring so I need to assign it. You gave a really good, comprehensive answer _directly related to the original question_, so I think it's only right that I assign you the bounty. Unfortunately it looks like my question, which initially appeared to be the same problem, won't be solved by your answer _even though solving my problem was my motivation for putting up the bounty_. So please don't lower the priority of the [Bug 542896](https://bugs.eclipse.org/bugs/show_bug.cgi?id=542896) you opened. Thank you! – Garret Wilson Dec 19 '18 at 00:07
  • This problem affects VS Code with Java 11 too. It shows the new message (The package javax.xml is accessible from more than one module: , java.xml), but I still don't know how to solve it in VS Code. The project builds fine in Maven. – marcus Mar 08 '19 at 18:56
  • @marcus if it's indeed the same issue, then your module dependencies are illegal and need to be fixed. Maven building fine would then simply reflect that you are using a compiler (javac) that still doesn't report this mandatory error (_or perhaps maven invokes the compiler with different options than what you have configured in Eclipse_). – Stephan Herrmann Mar 10 '19 at 19:18
  • 1
    Thanks, I guess I will need to exclude some transitive dependencies then (or update more libraries). – marcus Mar 11 '19 at 14:24
  • @StephanHerrmann OK, I excluded xml-apis, but some errors persist. What if the dependencies come from something like javax:javaee-api:8.0 or javax.xml.bind:jaxb-api:2.3.0? I thought they were the right and most up to date dependencies to add when you need this Java EE features in Java 11 (if a new question would be better, feel free to tell me so). – marcus Mar 11 '19 at 15:35
  • @marcus Sorry, I'm not really in the position to give recommendations for your project structure. The current thread here only deals with the question, whether or not it is correct to flag that situation as illegal, and we conclude, yes it is correct. From here, Eclipse is only the messenger. Some options that I know of, are: (consistently!) exclude "normal" dependencies or use `--limit-modules`. If this doesn't suffice and if there isn't yet a thread on strategies regarding xml-apis then, yes, a new question seeking recommendations could be a good idea. – Stephan Herrmann Mar 12 '19 at 10:33
  • 3
    Great answer. Would you consider writing a follow-up explaining the specific procedure to be followed, using the new UI, for someone that does not understand the precise rules of modular compilation? (I am thinking of students of mine learning Java, I can’t teach them all the complexity of Java in one go but still would like to expose them to interesting projects as soon as possible, where they might face this difficulty.) – Olivier Cailloux Jul 25 '19 at 09:04
  • @OlivierCailloux I proposed a conference presentation on the general topic as https://www.eclipsecon.org/europe2019/sessions/tweak-your-modules When the proposal is accepted and slides are prepared I will put them online (unless I forget ;X). – Stephan Herrmann Jul 26 '19 at 10:35
  • 7
    @OlivierCailloux Buried in the [Eclipse bug report thread at comment 51](https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928) are these short instructions that worked for me: "To exclude xml-apis.jar, open your POM in eclipse, go to the Dependency Hierarchy tab, filter by xml-api, right-click on any instance of xml-apis that appears, and choose Exclude Maven Artifact." – cb4 Aug 01 '19 at 02:04
  • 3
    Third solution: exclude `xml.apis` from the project dependencies. Drawbacks compared to excluding `java.xml` from the set of observable modules: 1) the dependency that introduced `xml.apis` as a transitive dependency (`xerces`, in my case) might work well with that specific version and misbehave with the one provided with the JRE (which might be older); 2) `xml.apis` might provide classes not included in the version provided with the JRE. But, similar risks exist with excluding the `java.xml` module (on which other components might depend). @StephanHerrmann: any thoughts? – Olivier Cailloux Aug 02 '19 at 12:53
  • 2
    Plus, `xml.apis:xml.apis:1.4.01` seems to be a subset of `java.xml` (as provided in OpenJDK 11): I found no class included in the former missing in the latter, except for `org.apache.xmlcommons.Version`, but conversely, many classes from `java.xml` are not in `xml.apis`. Thus I’d rather recommend to exclude `xml.apis` and keep the JRE module. – Olivier Cailloux Aug 02 '19 at 12:57
  • My DUMB workaround: Set project compiler as Java 1.8 and rebuild. We don't need any feature later than Java 8 so it's ok for now. – Alex Byrth Aug 04 '19 at 18:08
  • Is the answer still valid? I don't find this contents tab or details dialog in the latest version of Eclipse. Am I just missing it? – peter.petrov Jan 17 '22 at 19:58
  • @peter.petrov if you're looking for "Modularity Details" mentioned in Solution (3), just read down in the answer, upto the last bullet under "Edits". – Stephan Herrmann Jan 18 '22 at 20:05
  • @StephanHerrmann Thanks a lot! – peter.petrov Jan 18 '22 at 20:27
12

In my case the problem was that xercesImpl : 2.10.0 was a (transient) dependency. This jar bundles org.w3c.dom.html.HTMLDOMImplementation.

As far as I understand the org.w3c.dom package then becomes available from two modules, causing the build to fail. In case one of the dependencies (direct or transient) has classes in one of the 25 packages exported by the java.xml module your build will fail.

Excluding xercesImpl (and also the offenders listed below) in Maven solved the issue for me:

    <dependency>
        <groupId>xyz</groupId>
        <artifactId>xyz</artifactId>
        <version>1.0</version>
        <exclusions>
            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
            </exclusion>
            <exclusion>
                ...
            </exclusion>
        </exclusions>
    </dependency>

Thanks to Rune Flobakk for giving the hint here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928#c73

Other offenders:

  • batik-ext : 1.9 (bundles org.w3c.dom.Window)
  • xom : 1.2.5 (bundles org.w3c.dom.UserDataHandler)
  • stax-api : 1.0.2 (bundles javax.xml.stream.EventFilter)
  • xml-apis : 1.4.01 (bundles org.w3c.dom.Document)
  • xml-beans : 2.3.0 (bundles org.w3c.dom.TypeInfo)
Guillaume
  • 14,306
  • 3
  • 43
  • 40
10

While the accepted answer (by myself) is still correct, a further twist of the story was recently brought to my attention:

The original intention may have been to actually support the situation at hand.

See this quote in the original design document "The State of the Module System" (SotMS):

If a package is defined in both a named module and the unnamed module then the package in the unnamed module is ignored.

That document is dated 2016/3/8 08:18, and already at that time was marked "This document is slightly out of date". Moreover, it is not legally binding for any implementation. Still that document has some relevance since what's quoted above is precisely what javac appears to implement (and still implements many years after JDK-8215739 was filed).

IOW, the conflict is not so much a conflict between 1st and 2nd implementation, but a conflict even within Oracle, so it seems. 2 Votes for supporting the situation (SotMS and javac) and only one vote for disallowing (JLS).

Since Eclipse committers are not inclined to resolve this conflict within Oracle, the recent 2022-12 release of Eclipse has a new compiler option: by adding the following line to a project's .settings/org.eclipse.jdt.core.prefs, a user may opt to ignore JLS in this regard:

org.eclipse.jdt.core.compiler.ignoreUnnamedModuleForSplitPackage=enabled

This option puts the decision into the user's hands: do they want JLS-semantics or SotMS/javac semantics (in this particular issue)? Still we were not quite ready to provide a UI option for it, to avoid that users made this choice thoughtlessly, without the background information as provided here.

Personally, I'm not particularly happy about this situation, as it aggravates the fact that Java is not one, but several languages.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
  • 1
    worked for me with lowercase 'enabled' – Mike Feb 23 '23 at 18:11
  • Thanks, @Mike, I had taken the spelling of an internal constant instead of its value :) - corrected. – Stephan Herrmann Mar 06 '23 at 16:45
  • @StephanHerrmann, can this option be set any other way than in an Eclipse project preferences file? Think batch compiler (ECJ, AspectJ compiler). I need to configure this for IntelliJ IDEA and AJC, not for Eclipse IDE and ECJ (JDT Core). – kriegaex Apr 11 '23 at 08:28
  • @kriegaex can you directly pass this option into the compiler: https://github.com/eclipse-jdt/eclipse.jdt.core/commit/9b329b07f6ecc238fef4913cdbd8d2830eafd6ef#diff-564d1ddd6c5878b94b202b92b3f1831a8831a90fc06c320ccdf816b9b74cb9e5 ? – Stephan Herrmann Apr 12 '23 at 12:28
  • @StephanHerrmann: I had found that piece of code already. But it seems that my question is more basic: How do I pass the option into the compiler directly? What is the CLI syntax for it? Something like passing system properties to the JVM via `-DmyProperty=abc`? So far, I only managed to pass it in via config file. It does not seem to do what I want, but at least the option is recognised that way. – kriegaex Apr 12 '23 at 15:34
  • @kriegaex I gave that hint under the assumption that you are invoking the compiler from within Java, with no need for a detour via CLI. Using a property file might be the next best strategy. In that case it would be interesting to know in which way that fails. Feel free to open a GH issue and mention me on it. – Stephan Herrmann Apr 13 '23 at 14:40
  • No, I am not calling it from Java but from an IDE (IntelliJ) or from Maven. The funny thing is that the Maven build worked while the IntelliJ build did not, hence I started searching for the compilation errors I saw and found this setting. At this point, I admit that I am stupid and ugly, because the reason the setting did not work at first was sitting in front of the computer. AJC relocates the prefix `JavaCore.PLUGIN_ID` from `"org.eclipse.jdt.core"` to `"org.aspectj.org.eclipse.jdt.core"`, which I forgot, because I looked up the setting in the upstream source code, not in the AspectJ fork. – kriegaex Apr 13 '23 at 15:49
5

This seems to have been reported as Eclipse Bug 536928. Maybe if everyone were to go vote on it it would get them to raise the priority.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • unfortunately with the new eclipse version 2019-06, it is not possible anymore to change the order to resolve the issue – benez Jul 09 '19 at 12:40
  • [fixed](https://github.com/eclipse-jdt/eclipse.jdt.core/pull/424) – Mike Feb 23 '23 at 18:18
5

What happens here is you have a wildcard import like import org.w3c.dom.*, stating you want to import all classes from package org.w3c.dom. Now, if there's at least one class in org.w3c.dom provided by a second source, Java must not start (as pointed out here).

(By the way, the message "... cannot be resolved" is replaced by a more accurate error message "The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml" in more recent Eclipse versions, see this merged change request by Stephan Herrmann.)

To resolve this problem

  1. Open the "Open Type" dialog (Ctrl+Shift+T).
  2. Enter the complete import, so org.w3c.dom.* or org.w3c.dom..
  3. Check the entire list for multiple sources. All entries here should contain only something like "jdk-11-...".
  4. Gather all JARs that contain classes you have multiple sources for.
  5. Open the "Dependency Hirarchy" tab from pom.xml.
  6. Search for the JAR file.
  7. Add an exlusion (right click or edit the pom.xml manually).

Example

I had this findbugs dependency in my pom.xml:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>findbugs</artifactId>
    <version>${findbugs.version}</version>
</dependency>

Findbugs has two dependencies that need to be excluded:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>findbugs</artifactId>
    <version>${findbugs.version}</version>
    <exclusion>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
    </exclusion>
    <exclusion>
        <groupId>jaxen</groupId>
        <artifactId>jaxen</artifactId>
    </exclusion>
</dependency>
steffen
  • 16,138
  • 4
  • 42
  • 81
  • 1
    This worked for me. Moving to Java11 and a dependency from another dependency created the conflict. Once excluded in the POM then it just uses the dependency provided by Java. Mine was javax.xml.namespace.QName weblogic wlfullclient – Skystrider Apr 21 '20 at 14:34
  • 1
    I have tried many solutions, only this one worked for me. – Enchantres Feb 20 '22 at 16:01
5

While Stephan Herrmann's answer is the correct one, I'll post my error and how I got it solved if it can help others. I had the error The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xml and after inspecting the class with the error, it was the javax.xml.namespace.QName import that was complaining. With the "Open Type" dialog, I found out that it was pulled from stax-api through eureka client. This solved it for me :

<exclusion>
   <groupId>stax</groupId>
   <artifactId>stax-api</artifactId>
</exclusion>
jebeaudet
  • 1,533
  • 16
  • 15
  • "Open Type" was the key to fixing my problem. Thank you! – lilalinux Jul 24 '20 at 10:28
  • In my case it was xpp3 which came in via axon-messaging. Excluding xpp3 fixed it. – lilalinux Jul 24 '20 at 10:35
  • 1
    Thanks for this clue. I was having trouble identifying where the conflicting reference was coming from for org.w3c.dom.Document. Found it easily in Eclipse 2020-12 this way: Selected org.w3c.dom.Document within the import statement that Eclipse flagged, right-click and choose Open Type Hierarchy, in the Type Hierarchy dialog right click Document at the top and choose Implementors > Workspace to reveal all the JARs in all projects in the workspace which are bringing in org.w3c.dom.Document (or whatever type you have selected that is accessible from more than one module – MikeOnline Feb 25 '21 at 04:25
4

Have seen something very similar under Eclipse 4.8.0 and JDK 10. E.g.

import org.w3c.dom.Element;

was failing to compile in Eclipse with: The import org.w3c.dom.Element cannot be resolved

Even so, pressing F3 (Open Declaration) on that import, Eclipse was able to open the interface definition - in this case under xml-apis-1.4.01.jar.

Meanwhile, builds from Maven direct were working fine.

In this case the fix was to remove this dependency from the pom.xml:

    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>1.4.01</version>
    </dependency>

Then the compile errors in Eclipse melted away. Following F3 again showed the Element interface - now under the java.xml module, under the JRE System Library under the project. Also the Maven build remained fine.

This feels like a problem with Eclipse resolving a class that it finds in both a JDK module and dependent .jar file.

Interestingly, in a separate environment, this time under Eclipse 4.9.0 and JDK 11, all is fine, with or without the xml-apis:1.4.01 dependency.

df778899
  • 10,703
  • 1
  • 24
  • 36
  • Try cloning and building https://bitbucket.org/globalmentor/guise/commits/4dc75d8038b17d8fc9b3deeffb434aa36419871e . Note that I'm using Eclipse Enterprise 2018-12 M3 with the latest updates. – Garret Wilson Dec 11 '18 at 22:28
  • Managed to get that to build under Eclipse 4.9.0 + JDK 10. Clearly the problem there wasn't the `xml-apis` dependency, but found such as `import org.w3c.dom.*;` was still failing. Don't know if it's an option, but breaking these down to type level imports worked around the problem. Example updated version [here](https://github.com/df789/jdk10-eclipse) . The imports were fixed up using Eclipse's Organize Imports, so it looks like quite a lot of change. Happy to make that a proper answer if it works out for you. – df778899 Dec 12 '18 at 20:52
  • ... meant to say, the initial import of the projects wasn't good - NullPointerExceptions in the compiler. But after a Maven/Update Project on the projects, it compiled cleanly. – df778899 Dec 12 '18 at 21:09
  • But what about 2018-12 M3? I'm not going back to 4.9.0. I'm going forward with Java 11. I can't downgrade Eclipse! – Garret Wilson Dec 13 '18 at 02:03
  • Fine under 2018-12 RC1 + JDK 11 - the NullPointerExceptions were gone too – df778899 Dec 13 '18 at 19:18
  • So you're saying that removing wildcard imports will work around the problem? And is that only for the XML-related imports, or do I have to do it for all imports? And do I have to do it for all files, or just the files that have XML-related imports? – Garret Wilson Dec 14 '18 at 14:24
  • 1
    That's right. I think it may be any JDK level wildcard imports - e.g. `import java.net.*` was also a problem. Or maybe Eclipse has a problem with wildcard imports against modules in general. It affected 6 files in the source you referenced - changeset [here](https://github.com/df789/jdk10-eclipse/commit/3a989132a4abdab5073827628079df5db93b1be3) – df778899 Dec 14 '18 at 18:26
  • 1
    Just want to mention for anybody that encounters this issue that xercesImpl:2.12.0 also includes the org.w3c.dom.html package and could also very well be causing similar issues. – Thorsten Wendelmuth Apr 06 '19 at 08:20
3

This is more of a work-around, but from my experience it can be resolved by going to the "Java Build Path", the "Order and Export" tab, and sending the "Maven Dependencies" to the bottom (so it's below the "JRE System Library").

Yossi
  • 134
  • 1
  • 3
2

Thanks for this clue. I was having trouble identifying where the conflicting reference was coming from for org.w3c.dom.Document. Found it easily in Eclipse 2020-12 this way: Selected org.w3c.dom.Document within the import statement that Eclipse flagged, right-click and choose Open Type Hierarchy, in the Type Hierarchy dialog right click Document at the top and choose Implementors > Workspace to reveal all the JARs in all projects in the workspace which are bringing in org.w3c.dom.Document (or whatever type you have selected that is accessible from more than one module – MikeOnline yesterday

following the directions above from one of the earlier posts helped us solve our issue. what we did was replace Document with GenericDocument and Element with GenericElement from batik - and compile errors are gone - now we just have to test to make sure the implementation matches what we had under java 8. Thanks MikeOnline

0

jdk 9+ brought in changes related to project jigsaw. JDK was broken down into various modules and some modules, javaee, jaxb and xml related, are no more loaded by default. You should add these to your maven build directly, instead of expecting them to be in jre classpath. see this SO question

gagan singh
  • 1,591
  • 1
  • 7
  • 12
  • 1
    Thanks for your answer. I don't think the classes in question are part of the ones that are referred to in the other SO question. My problem classes all come from the maven dependency xml-apis-1.4.01. The dependency (as all other maven dependencies) is part of the build path. – Carsten Jun 29 '18 at 05:06
  • Which in the end does not change a thing you have to define a `module-info.java` definition file see https://www.oracle.com/corporate/features/understanding-java-9-modules.html otherwise it will not work. – khmarbaise Jun 29 '18 at 06:50
  • Thanks for your comment. I'm not sure this is right though. In the Eclipse path the maven dependency is in the CLASSPATH not in the MODULEPATH, so shouldn't it be treated like a non-module jar? Also why does it only affect this one jar out of many, many similar maven dependencies. Lastly why would only the Eclipse internal build report an error, while both command line maven and explicit maven build in Eclipse succeed? – Carsten Jul 01 '18 at 01:54
  • I'm having the same problem. I can successfully compile my project with javac, but Eclipse can't find these classes. Did you find a solution to this problem? – Tom Jul 10 '18 at 20:26
  • 2
    I marked this answer down because I don't see how it relates at all. This is a classpath issue, not a module issue. Moreover it works with Maven+JDK on the command line. If it works with Maven+JDK but not in Eclipse, the problem is in Eclipse, and all the prose about how JDK was broken down into modules is ancillary and, while interesting and not necessarily incorrect, is nevertheless irrelevant. – Garret Wilson Dec 10 '18 at 20:50