Java Ant-build脚本找不到属性文件中定义的pathelement

Java Ant-build脚本找不到属性文件中定义的pathelement,java,ant,build,Java,Ant,Build,我有一个ant构建脚本,它有以下目标: <target name="_initLiveProps"> <property file="buildscripts/live.properties"/> </target> <target name="buildLive" depends="_initLiveProps"> <property file="buildscripts/live.properties"

我有一个ant构建脚本,它有以下目标:

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

<target name="buildLive"  depends="_initLiveProps">
        <property file="buildscripts/live.properties"/>
</target>
当我构建项目(使用ant buildLive)时,会出现编译错误,主要是因为它找不到product-def.jar中定义的类

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

<property name="myclasspath" refid="project.class.path"/>
<echo message="${myclasspath}" />
定义属性文件中定义的路径元素的正确方法是什么

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

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

定义放入


是的,这可能会起作用,但我有太多的目标取决于路径,我不能真正把每一个目标的定义。也许我可以创建一个它们都依赖的新目标。@ziggy这就是我的意思-将
定义放在加载属性文件的同一个目标中,可能所有需要路径的目标都已经依赖于此。我的意思是,还有其他目标不依赖于_initLiveProps目标。例如,加载开发属性的目标不依赖于加载活动属性文件的目标。@ziggy我现在明白你的意思了。我用一种可能的方法编辑了我的答案-您需要将现有的
\u init…
目标重命名为其他目标,然后声明一个新目标,该目标依赖于旧的
\u init…
,后跟创建
的目标。仅仅让现有的
\u init…
依赖于类路径目标是行不通的,因为它会以错误的顺序进行操作。
product-def.jar=./../lib/product-def/live/product-def.jar
<property name="myclasspath" refid="project.class.path"/>
<echo message="${myclasspath}" />
<pathelement location="${product-def.jar}"/>
<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>
<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" />