16

I migrating a maven project in Java 8 to a Java 9 project without any build tool in Eclipse OxyGen 1a.

So my module-info.java looks like this:

enter image description here

But java.xml.bind is not accessible, although its in my module path:

enter image description here

So what is wrong here?

Naman
  • 27,789
  • 26
  • 218
  • 353
user3133542
  • 1,695
  • 4
  • 21
  • 42
  • 2
    see https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j/43574427?noredirect=1#comment80650142_43574427 – Andy Guibert Oct 20 '17 at 15:28
  • 3
    That module is [deprecated](https://docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html). You will need to JAXB as an external library. – VGR Oct 20 '17 at 15:30
  • @VGR But it's available in JDK9, so it must be available in Eclipse – ZhekaKozlov Oct 20 '17 at 15:40
  • 1
    It exists in JDK 9, but it’s not in the default module path. – VGR Oct 20 '17 at 15:49
  • I suspect Eclipse is just not fully ready yet for Java 9 – ZhekaKozlov Oct 20 '17 at 15:55
  • 4
    `requires java.xml.bind` should work. As noted by others, the module is deprecated-for-removal in Java SE but this module leads a double life and so will live on if jettisoned from the JDK. The standalone version, as of version 2.3.0, is an explicit module that you can deploy on the module path (or upgrade module path to override the version in the JDK). To your question, if it works outside of Eclipse then it hints of something in the Eclipse environment. – Alan Bateman Oct 20 '17 at 16:36
  • 2
    [Related answer](https://stackoverflow.com/a/46221811/1746118) for the migration of these API's. – Naman Oct 21 '17 at 07:08

1 Answers1

16

When compiling an unnamed module, java.xml.bind is not accessible by default, but in a modular project (as in this question) failing to resolve reference to module java.xml.bind was a bug (see edit below).

To work around this until the bug is fixed, you can explicitly include module java.xml.bind by double click on Is modular (see screenshot in the question), and in the dialog that shows, move the desired module from Available modules to Explicitly included modules:

Module properties dialog

Edit: Bug 526054 has been resolved in Eclipse Oxygen.2, and thus a modular project should no longer need the steps above (which are still relevant for code in an unnamed module, though).

Edit 2: In Eclipse 2019-06 the UI for tasks like above has been revamped. Up-to-date documentation can be found in the online help.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38
  • I see a downvote and the answer has not been accepted, which let's me ask: what do you see missing? – Stephan Herrmann May 29 '18 at 09:43
  • Sorry for the late response. Other projects required my attention. So to this issue: it turned out to be a mix of some eclipse problems in combination with jdk9 or newer (just like you already mentioned). Especially when using multi version jars containing builds for different jdks. This SHOULD be fixed in eclipse by now. Will give it a new try in the comming days. No idea why i can't mark your answer as the correct answer though... – Ulathar Sep 18 '18 at 10:49