Ant javac构建没有正确地获取类路径元素和编译失败



我继承了一个以前在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>

在将构建机器升级到Java8之后,Ant抱怨命令行太长。

因此,我们被指示更改构建文件,以便而不是不使用fileset元素,而是使用pathelementbuild.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}下的一些JAR。例如,出现以下情况(经过编辑(:

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为什么在这里失败,以及我们如何在不中断编译过程的情况下将数十个jar导入类路径。我也无法显示类路径中有效地包含了哪些jar。

您可以使用pathconvert来记录(echo(路径,请参阅Ant pathconvert不接受换行

如果路径对于命令行来说太长,您可以尝试从pathconvert结果创建一个文件(前缀为"-cp"(,并将其用作@argfile";有关javac,请参阅https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#BHCCFGCD

在Ant中,应该可以传递"@argfile";使用javac任务的compilerarg元素。

最新更新