如果找不到类路径上的文件夹,如何使ant不会失败

时间:2013-02-28 14:07:18

标签: ant

我正在尝试修改我的ant脚本,以便无论是否存在本地lib文件夹,它都可以无错误地构建。我想在多个战争中使用相同的脚本,其中一些将具有WEB-INF / lib,而其中一些则不具备。如果文件夹存在,请将其包含在类路径中,否则请不要包含它。我尝试过但我无法弄清楚应该去哪里。我认为这应该比我实现的要简单得多,但我的Googl Fu让我失望了。

<property name="local.libs" value="WebContent/WEB-INF/lib" /> 
<path id="local.libs.path">
<fileset dir="${local.libs}" includes="*.jar" />
</path>
<target name="compile">
    <mkdir dir="${build.classes.dir}"/>
    <javac srcdir="${src.java.dir}" destdir="${build.classes.dir}" debug="true" includeantruntime="false">
        <compilerarg value="-Xlint:-path" />
        <classpath refid="local.libs.path" />
                    <classpath refid="server.libs.path" /> <!-- not referenced in snippet -->
    </javac>
</target>

1 个答案:

答案 0 :(得分:1)

我最终通过将local.libs的值设为WebContent / WEB-INF来解决这个问题:

<property name="local.libs" value="WebContent/WEB-INF" />

然后是文件集

<fileset dir="${local.libs}" includes="*lib/*.jar" />

然后它将构建是否存在lib文件夹。

相关问题