我正在尝试使用Java 10,Ant和Eclipse编译器编译这个简单的代码:
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>();
}
}
这是我正在使用的Ant文件:
<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>
如果我使用javac(compile-javac target),代码编译得很好,但我无法使用4.7.3a或4.8RC2 Eclipse编译器:
release="10"
source="10" and target="10"
而不是release="10"
,则源级别错误消失但我得到无效的模块名称:javax.xml.bind 错误print-version-info目标提供以下输出:
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
可能是ecj bug 487421的后续工作,还是我不了解命令行选项?