【问题标题】:Ant try to compile to 1.6 when target is set to 1.5当目标设置为 1.5 时,Ant 尝试编译为 1.6
【发布时间】:2017-02-05 09:25:14
【问题描述】:

我已经为 javac ant 任务问题苦苦挣扎了很长时间。问题在于显然 ant 忽略了设置为 1.5 的目标属性:

    <target name="compile" description="Kompilacja zrodel" depends="init">
    <javac target="${compile.targetvm}" source="${compile.sourcecompatibility}" debug="${compile.debug}" optimize="${compile.optimize}" verbose="${compile.verbose}" srcdir="${source.dir}" destdir="${build.classes.dir}" encoding="${compile.source.encoding}" includeantruntime="false">
        <classpath refid="compile.classpath" />
    </javac>
</target>

目标和源设置为 1.5。 当我运行任务时出现编译错误:

foo.Bar is not abstract and does not override abstract method createStruct(java.lang.String,java.lang.Object[]) in java.sql.Connection

根据 java docs (link) 方法 createStruct 是在 java 1.6 中引入的,所以我知道 ant 正在编译为 1.6 而不是 1.5,因为我礼貌地要求他这样做。

我从 Eclipse 和命令行运行任务,结果相同,所以这不是 Eclipse 问题。我试图更改 ANT 中的 JRE 并使用不同的 ANT 版本,但没有任何帮助。

我已经尝试了所有可以在网上找到的东西,现在我放弃了。有人可以帮助我吗?漂亮请..

【问题讨论】:

  • 指定源兼容性只控制语言语法,而不是 Java 运行时库。由于您没有告诉 Ant 在哪里可以找到 Java 1.5 运行时库,因此它使用的是用于调用 Ant 的同一个库。
  • 要修复,在指定&lt;path id="compile.bootclasspath"&gt;&lt;fileset dir="${java15.home}/jre/lib" includes="*.jar"/&gt;&lt;/path&gt;后指定bootclasspathref="compile.bootclasspath"
  • 是的!这样可行!非常感谢:) 你应该把它作为答案,这样我就可以接受它

标签: java ant javac


【解决方案1】:

指定源兼容性只控制语言语法,而不是 Java 运行时库。

由于您没有告诉 Ant 在哪里可以找到 Java 1.5 运行时库,它使用的是用于调用 Ant 的同一个库。

要修复,请同时指定bootclasspathref="compile.bootclasspath" 属性。

compile.bootclasspath 是这样定义的:

<path id="compile.bootclasspath">
    <fileset dir="${java15.home}/jre/lib" includes="*.jar"/>
</path>

java15.home 是什么应该很明显。 ;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-04
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    相关资源
    最近更新 更多