蚂蚁 - 构建脚本没有找到一个属性文件中定义pathelement [英] Ant - build script does not find pathelement defined in a properties file

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

问题描述

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

 <目标名称=_ initLiveProps>
        <物业档案=buildscripts / live.properties/>
< /目标与GT;<目标名称=buildLive取决于=_ initLiveProps>
        <物业档案=buildscripts / live.properties/>
< /目标与GT;

在构建脚本我有几个pathelements声明,如下所示:

 <路径ID =project.class.path>
        < pathelement位置=./../的lib /的log4j-1.2.16.jar/>
        < pathelement位置=$ {产品def.jar}/>
< /路径>

该产品def.jar定义在buildscripts / live.properties文件中定义为

 产品def.jar = / .. / lib目录/产品的高清/生活/产品def.jar

当我建立项目(使用蚂蚁buildLive)我得到的编译错误,主要是因为它无法找到产品def.jar中定义的类。

我想打印出来的类路径如下图所示。

 <属性名=myclasspathREFID =project.class.path/>
<回声消息=$ {} myclasspath/>

和输出出来为 C:\\产品\\ LIB \\的log4j-1.2.16.jar; C:\\产品\\ $ {产品def.jar}

上面表明以下定义是不正确的

 < pathelement位置=$ {产品def.jar}/>

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

修改

我认为这个问题是,在buildLive目标加载属性文件之前project.class.path的定义被初始化。
是否有延迟project.class.path的初始化以后才buildLive的目标已经完成了一个办法吗?


解决方案

  

有延缓project.class.path的初始化以后才buildLive的目标已经完成了一个办法吗?


<路径> 里面定义的<目标>

 <目标名称=_ initLiveProps>
        <物业档案=buildscripts / live.properties/>
        &所述;路径ID =project.class.path>
                < pathelement位置=./../的lib /的log4j-1.2.16.jar/>
                < pathelement位置=$ {产品def.jar}/>
        < /路径>
< /目标与GT;

<路径方式> 将是可见的依赖(直接或间接)在这一个所有目标

如果您有加载不同性质几个不同的目标,例如 _initLiveProps _initDevProps 等等,那么你可以把<路径> 定义成一个共同的目标如下:

 <目标名称=类路径>
        &所述;路径ID =project.class.path>
                < pathelement位置=./../的lib /的log4j-1.2.16.jar/>
                < pathelement位置=$ {产品def.jar}/>
        < /路径>
< /目标与GT;<目标名称=_ loadLiveProps>
        <物业档案=buildscripts / live.properties/>
< /目标与GT;
<目标名称=_ initLiveProps取决于=_ loadLiveProps,类路径/><目标名称=_ loadDevProps>
        <物业档案=buildscripts / dev.properties/>
< /目标与GT;
<目标名称=_ initDevProps取决于=_ loadDevProps,类路径/>

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>

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

product-def.jar=./../lib/product-def/live/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}" />

And the output comes out as 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?

Edit

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?

解决方案

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

Put the <path> definition inside the <target>

<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.

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" />

这篇关于蚂蚁 - 构建脚本没有找到一个属性文件中定义pathelement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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