Ant - 构建脚本找不到属性文件中定义的路径元素 [英] Ant - build script does not find pathelement defined in a properties file

查看:26
本文介绍了Ant - 构建脚本找不到属性文件中定义的路径元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下目标的 ant 构建脚本:

I have an ant build script that has the following targets:

<target name="_initLiveProps">
        <property file="buildscripts/live.properties"/>
</target>

<target name="buildLive"  depends="_initLiveProps">
        <property file="buildscripts/live.properties"/>
</target>

在构建脚本中,我声明了几个路径元素,如下所示:

Within the build script i have several pathelements declared as shown below:

<path id="project.class.path">      
        <pathelement location="./../lib/log4j-1.2.16.jar" />
        <pathelement location="${product-def.jar}"/>
</path>

product-def.jar 定义在 buildscripts/live.properties 文件中定义为

The product-def.jar definition is defined in the buildscripts/live.properties file as

product-def.jar=./../lib/product-def/live/product-def.jar

当我构建项目(使用 ant buildLive)时,我收到编译错误,主要是因为它找不到 product-def.jar 中定义的类.

When i build the project (using ant buildLive) i get compilation errors and mainly because it cannot find classes defined within product-def.jar.

我尝试打印出如下所示的类路径

I tried to print out the classpath as shown below

<property name="myclasspath" refid="project.class.path"/>
<echo message="${myclasspath}" />

输出结果为 c:\product\lib\log4j-1.2.16.jar;c:\product\${product-def.jar}

以上说明以下定义不正确

The above suggests that the following definition is not correct

<pathelement location="${product-def.jar}"/>

定义在属性文件中定义的路径元素的正确方法是什么?

What is the correct way of defining a path element that is defined in a properties file?

我认为问题在于 project.class.path 的定义是在将属性文件加载到 buildLive 目标之前初始化的.有没有办法将 project.class.path 的初始化延迟到 buildLive 目标完成之后?

I think the issue is that the definition for project.class.path is initialised before the properties file is loaded in the buildLive target. Is there a way to delay the initialisation of project.class.path until after buildLive target has completed?

推荐答案

有没有办法将 project.class.path 的初始化延迟到 buildLive 目标完成之后?

Is there a way to delay the initialisation of project.class.path until after buildLive target has completed?

定义放在

<target name="_initLiveProps">
        <property file="buildscripts/live.properties"/>
        <path id="project.class.path">      
                <pathelement location="./../lib/log4j-1.2.16.jar" />
                <pathelement location="${product-def.jar}"/>
        </path>
</target>

将对所有(直接或间接)依赖于该目标的目标可见.

The <path> will be visible to all targets that depend (directly or indirectly) on this one.

如果您有多个加载不同属性的不同目标,例如_initLiveProps_initDevProps 等,那么你可以把 定义放到一个公共目标中,如下

If you have several different targets that load different properties, e.g. _initLiveProps, _initDevProps, etc. then you could put the <path> definition into a common target as follows

<target name="classpath">
        <path id="project.class.path">      
                <pathelement location="./../lib/log4j-1.2.16.jar" />
                <pathelement location="${product-def.jar}"/>
        </path>
</target>

<target name="_loadLiveProps">
        <property file="buildscripts/live.properties"/>
</target>
<target name="_initLiveProps" depends="_loadLiveProps, classpath" />

<target name="_loadDevProps">
        <property file="buildscripts/dev.properties"/>
</target>
<target name="_initDevProps" depends="_loadDevProps, classpath" />

这篇关于Ant - 构建脚本找不到属性文件中定义的路径元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆