Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Ant build.xml文件无法使用fileset元素中的属性_Java_Ant_Path_Build.xml - Fatal编程技术网

Java Ant build.xml文件无法使用fileset元素中的属性

Java Ant build.xml文件无法使用fileset元素中的属性,java,ant,path,build.xml,Java,Ant,Path,Build.xml,我正在使用ant build.xml构建我的简单war文件 <?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.nam

我正在使用ant build.xml构建我的简单war文件

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

上面显示的ant build.xml工作得非常好。但是,在path标记中,如果我将dir=“lib”替换为dir=“${lib.dir}”(在文件集标记中),那么构建将失败,并出现如下所示的错误

构建失败 c:\Java\code\cillar\build.xml:22:c:\Java\code\cillar\${lib.dir}不存在


有人知道为什么会发生这种情况吗?

类路径是在加载构建文件时定义的,而属性仅在执行init目标时定义


将属性定义移到
init
目标之外,或将文件集定义移到执行
init
之后执行的目标中。

为什么要定义
并内联添加更多属性,尝试删除属性include并再次尝试将
替换为:
。那有帮助吗?谢谢。把房子搬到外面,它就像一个符咒。