2

I think the problem is the same as described in this blog post but I get this for Java 10: I have an Eclipse RCP application that uses Java 10 features but also JAXB classes. In Eclipse, I have to add the java.xml.bind module to the build path configuration of my project (as described here) to let the compile errors go away.

However, when building the product with Tycho 1.2.0 I get the following error, exactly for the class that uses JAXB:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.2.0:compile (default-compile) on project epd-editor: Compilation failure: Compilation failure:
[ERROR] ...app\src\app\editors\XmlPage.java:
[ERROR] package app.editors;
[ERROR] ^
[ERROR] Internal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.lookup.BinaryModuleBinding.create(BinaryModuleBinding.java:64)
[ERROR] java.lang.NullPointerException
[ERROR] at org.eclipse.jdt.internal.compiler.lookup.BinaryModuleBinding.create(BinaryModuleBinding.java:64)
[ERROR] at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getModuleFromAnswer(LookupEnvironment.java:427)
[ERROR] at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForTypeFromModules(LookupEnvironment.java:367)
[ERROR] at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:228)
[ERROR] at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:105)

Is there a way to configure the Tycho compiler plugin so that it can see modules like java.xml.bind or is there another reason for this error?

Thanks.

Michael
  • 4,722
  • 6
  • 37
  • 58

2 Answers2

1

There are three ways you can include modules from the java.se.ee aggregator module, which is not included for compile or runtime in JDK 10. (As of JDK 11, these modules will be removed from the JDK).

  1. The simplest is to use the command line option, --add-modules java.xml.bind. This will use the version that is still included in the JDK.
  2. Find a JAXB implementation jar. Maven central is a good place to go for this, there is also a reference implementation for JSR 222 (JAXB), which is part of the Java Web Services Developer Pack (http://www.oracle.com/technetwork/java/webservicespack-jsp-140788.html) but this is waaaay old and may not be the best choice. You can add where you've downloaded the jar to the upgrade module path using --upgrade-module-path {path}
  3. An alternative to 2 is to simply put the jar containing JAXB on the classpath.

I'm not familiar with Tycho but you would need to figure out how to use one of these methods with its configuration.

Speakjava
  • 3,177
  • 13
  • 15
1

Java EE modules are deprecated for removal and not resolved by default and will be removed in Java 11. The best way to handle this is to use a third-party dependency, but as you observe JDT trips over its own feet when that is done. I opened an issue and it was fixed some time ago, but it's not easy to find an artifact that contains the change and works on Java 10. The first artifact I know of comes from Eclipse Photon I20180531-0700.

Execute the following in Eclipse's plugins folder (@people from the future: you may have to update the version):

mvn install:install-file \
    -Dfile=org.eclipse.jdt.core_3.14.0.v20180528-0519.jar \
    -DgroupId=org.eclipse.tycho \
    -DartifactId=org.eclipse.jdt.core \
    -Dversion=3.14.0.v20180528-0519 \
    -Dpackaging=jar

You can then use it as follows as dependencies for Maven's compiler plugin:

<dependency>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-compiler-jdt</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <!-- unreleased version that was pulled from Eclipse Photon I20180531-0700
            contains the fix and compiles Java 10 -->
    <version>3.14.0.v20180528-0519</version>
</dependency>

The problem is also described on java9.wtf with a demo project on GitHub. (I forgot to push, so it's only online for about five minutes now. )

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255