[英]Ant javac build not correctly taking classpath elements and compilation failure
我继承了一个遗留项目,该项目过去在 Java 6 上构建,现在必须在基于 IBM Jazz RTC 的 DevOps 场景中构建在 Java 8 上。
以前,javac 编译器是使用以下类路径调用的
<path id="build.classpath">
<fileset dir="${lib.artifactory}" includes="*.jar"/>
<fileset dir="${common.lib.dir}" includes="*.jar"/>
<fileset dir="${wls.lib.dir}" includes="*.jar"/>
<fileset dir="${app.inf.lib.dir}" includes="*.jar"/>
<fileset dir="${web.inf.lib.dir}" includes="*.jar"/>
<fileset dir="${myEar.dir}" includes="*.jar"/>
<fileset dir="${weblogic.modules}" includes="*.jar"/>
<pathelement location="${weblogic.jar}"/>
</path>
将构建机器升级到 Java 8 后,Ant 抱怨命令行太长。
因此,我们被指示更改构建文件,以便不使用fileset
元素,而是使用pathelement
元素。 build.xml
如下:
<path id="build.classpath">
<pathelement location="${common.lib.dir}/*"/>
<pathelement location="${wls.lib.dir}/*"/>
<pathelement location="${app.inf.lib.dir}/*"/>
<pathelement location="${web.inf.lib.dir}/*"/>
<pathelement location="${myEar.dir}/*"/>
<pathelement location="${lib.artifactory}/*"/>
<pathelement location="${weblogic.modules}/*"/>
<pathelement location="${weblogic.jar}"/>
<pathelement location="${wfm.jar}"/>
</path>
<target name="compile" depends="init">
<javac target="${javacSourceTarget}" source="${javacSourceTarget}" debug="true" executable="${param.compilatore.executable}" fork="true" memoryMaximumSize="256m" srcdir="${srcWAR.dir}" destdir="${build.dir}" classpathref="build.classpath">
<include name="${maijava}" />
<include name="${package}/**/*" />
<include name="${package2}/**/*" />
<include name="${package3}/**/*" />
<include name="${package4}/**/*" />
<include name="${package5}/**/*" />
<exclude name="${packagejdo}" />
</javac>
</target>
( javac
任务没有改变)
所以,现在构建失败了,因为它找不到位于${app.inf.lib.dir}
下的一些 JARs 。 例如,发生以下(已编辑):
2022-09-05 13:11:29 [ExecTask ] [javac] Compiling 15 source files to /build/myEar_SRC/WORKAREA/elfi/classes
2022-09-05 13:11:29 [ExecTask ] [javac] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=ISO-8859-1
2022-09-05 13:11:38 [ExecTask ] [javac] /build/myEar_SRC/SRC/elfi/war/src/com/acme/frontend/profilo/BeanProfilo.java:7: package com.acme.client does not exist
2022-09-05 13:11:38 [ExecTask ] [javac] import com.acme.client.Response;
2022-09-05 13:11:38 [ExecTask ] [javac] ^
2022-09-05 13:11:38 [ExecTask ] [javac] /build/myEar_SRC/SRC/elfi/war/src/com/acme/frontend/profilo/BeanProfilo.java:8: package com.acme.utils does not exist
2022-09-05 13:11:38 [ExecTask ] [javac] import com.acme.utils.LogManager;
我们对${app.inf.lib.dir}
指向的 SFTP 目录进行了三次检查,并且 jar 存在。
我想了解为什么 Ant 在这里失败,我们如何在不破坏编译过程的情况下将数十个 jars 导入类路径。 我也无法显示哪些 jars 有效地包含在类路径中。
您可以使用 pathconvert 记录(回显)路径,请参阅Ant pathconvert is not accepting newlines
如果命令行的路径太长,您可以尝试从 pathconvert 结果创建一个文件(以“-cp”为前缀)并将其用作 javac 的“@argfile”,请参阅https://docs.oracle.com /javase/8/docs/technotes/tools/windows/javac.html#BHCCFGCD
在 Ant 中,应该可以使用 javac 任务的 compilerarg 元素传递该“@argfile”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.