質問

I am using an ant build.xml to build my simple war file.

<?xml version="1.0" ?> 
<project name="cellar" default="war">

  <target name="init">
    <property file="${user.home}/build.properties"/>
    <property name="app.name" value="${ant.project.name}"/>
    <property name="src.dir" location="src"/>
    <property name="lib.dir" location="lib"/>
    <property name="build.dir" location="build"/>
    <property name="dist.dir" location="dist"/>
    <property name="classes.dir" location="${build.dir}/classes"/>

    <mkdir dir="${build.dir}"/>
    <mkdir dir="${dist.dir}" />
  </target>

  <path id="classpath">
    <fileset dir="lib">
      <include name="*.jar"/>
    </fileset>
  </path>

  <target name="compile" depends="init" >
    <javac destdir="${classes.dir}" debug="true" srcdir="${src.dir}">
      <classpath refid="classpath"/>
    </javac>
  </target>

  <target name="war" depends="compile" >
    <war destfile="${dist.dir}/${app.name}.war" webxml="${src.dir}/main/webapp/WEB-INF/web.xml">
        <fileset dir="${src.dir}/main/webapp/"/>
        <lib dir="${lib.dir}"/>
        <classes dir="${classes.dir}"/>
    </war>
  </target>

  <target name="clean">
    <delete dir="${dist.dir}" />
    <delete dir="${build.dir}" />
  </target>

</project>

The ant build.xml shown above works perfectly. However in the path tag if I replace the dir="lib" with dir="${lib.dir}" (within the fileset tags) then the build fails and I get an error like that shown below

BUILD FAILED c:\Java\code\Cellar\build.xml:22: c:\Java\code\Cellar\${lib.dir} does not exist.

Does anyone know why this happens?

役に立ちましたか?

解決

The classpath is defined when the build file is loaded, whereas the properties are only defined when the init target is executed.

Move the properties definition outside of the init target, or move the fileset definition in a target executed after init is executed.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top