4

I am trying to compile this simple code using Java 10, Ant and the Eclipse compiler:

import java.util.ArrayList;
import javax.xml.bind.JAXBException;

class Test {
    void foo() throws JAXBException {
        throw new JAXBException("hi there");
    }

    void bar() {
        new ArrayList<String>();
    }
}

This is the Ant file I am using:

<project name="Java 10 test">

    <target name="compile-javac" depends="clean, print-version-info">
        <javac release="10" includeantruntime="false">
            <src path="."/>
            <compilerarg value="--add-modules"/>
            <compilerarg value="java.xml.bind"/>
        </javac>
    </target>

    <target name="compile-ecj-4.7" depends="clean, print-version-info">
        <javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
            release="10" includeantruntime="false">
            <src path="."/>
            <compilerclasspath>
                <pathelement path="ecj-4.7.3a.jar"/>
            </compilerclasspath>
            <compilerarg value="--add-modules"/>
            <compilerarg value="java.xml.bind"/>
        </javac>
    </target>

    <target name="compile-ecj-4.8" depends="clean, print-version-info">
        <javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
            release="10" includeantruntime="false">
            <src path="."/>
            <compilerclasspath>
                <pathelement path="ecj-4.8RC2.jar"/>
            </compilerclasspath>
            <compilerarg value="--add-modules"/>
            <compilerarg value="java.xml.bind"/>
        </javac>
    </target>

    <target name="clean">
        <delete file="Test.class"/>
    </target>

    <target name="print-version-info">
        <echo message="Java home is ${java.home}"/>
        <echo message="Java version is ${java.version}"/>
        <echo message="Ant version is ${ant.version}"/>
    </target>

</project>

The code compiles fine if I'm using javac (compile-javac target) but I can't get it to work with either the 4.7.3a or 4.8RC2 Eclipse compilers:

  • with 4.7.3a, I get the error parameterized types are only available if source level is 1.5 or greater even though I specify release="10"
  • with 4.7.3a, if I use source="10" and target="10" instead of release="10", the source level error disappears but I get a invalid module name: javax.xml.bind error
  • with 4.8RC2, I get the source level error and another JAXBException cannot be resolved to a type error, even though I specify that I would like to add the java.xml.bind module where JAXBException is defined.

The print-version-info target gives the following as output:

print-version-info:
     [echo] Java home is C:\Program Files\Java\jdk-10
     [echo] Java version is 10
     [echo] Ant version is Apache Ant(TM) version 1.10.3 compiled on March 24 2018

May be it is a follow up for ecj bug 487421 or I just don't understand the command line options?

ph8c4
  • 96
  • 1
  • 7
  • Quite interesting, since ANT states to ignore the source and target attribute version > 1.9 and when executed on Java >= 9. https://ant.apache.org/manual/Tasks/javac.html – Rainer Jun 05 '18 at 07:45
  • 1
    Did you try the "modulepath" parameter? Same link – Rainer Jun 05 '18 at 07:48
  • @Rainer: you're right, I can compile when adding --module-path=${java.home}/jmods, but only when using 4.8, not 4.7.3a. There I still get the source level error. I don't think that adding the module path for the JDK should be necessary, I guess I'll open a bug with the JDT guys. – ph8c4 Jun 05 '18 at 08:32
  • This is the bug I have opened: https://bugs.eclipse.org/bugs/show_bug.cgi?id=535552 – ph8c4 Jun 05 '18 at 11:45
  • Thanks - would be nice if you comment here the results of the bug when resolved as an answer. Cheers – Rainer Jun 06 '18 at 07:07

0 Answers0