2011-04-14 224 views
1

我有2個Ant構建腳本命名爲 「構建」 和 「tarne」Ant構建腳本問題

體形:

<?xml version="1.0" ?> 
<project name="build" default="zip"> 

    <property name="project.name" value="projectName"/> 
    <property name="version" value="default_version_value"/> 


    <taskdef resource="net/sf/antcontrib/antcontrib.properties"> 
     <classpath> 
      <pathelement location="lib/build/ant-contrib.jar"/> 
     </classpath> 
    </taskdef> 

    <var name="version2" value="default_version_value"/> 


    <property name="tmp" value="tmp"/> 
    <property name="build.dir" location="${tmp}/component/${project.name}"/> 
    <property name="java.classes" location="${tmp}/component/${project.name}/classes"/> 
    <property name="weblayout.dir" location="${tmp}/weblayout/resources/${project.name}"/> 


    <path id="compile.classpath"> 
     <fileset dir="lib" includes="**/*.jar" /> 
     <fileset dir="lib/build" includes="*.zip" /> 
    </path> 

    <target name="clean"> 
     <delete dir="${tmp}" /> 
    </target> 

    <target name="init" depends="clean"> 
     <mkdir dir="${java.classes}" /> 
    </target> 

    <target name="compile" depends="init"> 
     <javac srcdir="src" source="1.5" target="1.5" encoding="utf-8" includes="**/*.java" destdir="${java.classes}" classpathref="compile.classpath" /> 
    </target> 

    <target name="copy-resources" depends="compile"> 

      //Lots of copying here 

    </target> 

    <target name="read.version" description="Parses the hda file for your version number"> 

     <property file="${project.name}.hda" prefix="hda"/> 
     <propertyregex property="version" input="${hda.version}" regexp="\." replace="-" global="true" override="true"/> 
     <var name="version2" value="${version}"/> 

     <echo>${version}</echo> 
     <echo>${version2}</echo> 


    </target> 

    <target name="zip" depends="copy-resources, read.version" description="Package component"> 

     <zip destfile="${project.name}-${version}.zip" basedir="${tmp}" /> 
     <delete dir="${tmp}" /> 

    </target> 


</project> 

Tarne:

<?xml version="1.0" ?> 
<project default="tarne"> 

    <include file="build.xml"/> 
    <property name="project.name" value="build.project.name"/> 

    <target name="tarne"> 

     <antcall target="build.read.version" inheritRefs="true"></antcall> 
     <property name="version" value="build.version"/> 
     <property name="version2" value="build.version2"/> 

     <echo>${version}</echo> 
     <echo>${version2}</echo>  



    </target> 

</project> 

和輸出我是說我運行tarne.xml是:

Buildfile: tarne.xml 
tarne: 
build.read.version: 
    [echo] v1-0-1 
    [echo] v1-0-1 
    [echo] default_version_value 
    [echo] default_version_value 

那裏杉木st 2行(v1-0-1)來自build.xml的read.version目標,接下來的兩行來自tarne.xml。總的想法是我應該能夠在我的tarne.xml構建腳本中訪問版本號。

關於發生什麼問題的任何想法?

回答

2

Antcall不支持你打算做什麼:

http://ant.apache.org/manual/Tasks/antcall.html: 被叫目標(S)的一個新項目運行;請注意,這意味着被調用目標設置的屬性,引用等不會保留回調用項目。

你可以嘗試:

<target name="tarne" depends="build.read.version"> 
    </target> 

這將保留新值。

+0

工作正常,但是Eclipse正在向我發送消息「Target build.read.version在此項目中不存在」(它運行正常,只是Eclipse無法在導入時找到目標)消息。任何關於如何獲得傳球的想法? – Peeter 2011-04-14 08:56:36

+1

depends =「read.version」應該是正確的,因爲您導入build.xml – oers 2011-04-14 08:59:51

0

嘗試

<property name="version" value="${build.version}"/>   
<property name="version2" value="${build.version2}"/>