Search code examples
eclipsemaveneclipse-rcptychojava-10

Eclipse Tycho: Compile error when using the java.xml.bind module?


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.


Solution

  • 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. 😒)