Ant 错误:未找到引用 ${lib.classpath}



当我尝试使用 ant 构建我的项目时,我收到错误。下面是构建文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="GPClient" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <dirname property="client.basedir" file="${ant.file.GPClient}"/>
  <property name="client.src" location="${client.basedir}/src"/>
  <property name="client.build" location="${client.basedir}/build"/>
  <property name="client.dist"  location="${client.basedir}/dist"/>
  <property name="client.done"  location="${client.basedir}/done"/>
  <property name="client.app"  location="${client.basedir}/app"/>
  <property name="client.webinf_classes" location="${client.basedir}/WEB-INF/classes"/>
  <property name="server.dir" location="${client.basedir}/../GrahamsProjServer"/>
  <property name="deploy.location"  location="${client.basedir}/../../jboss-as-7.1.1.Final/standalone/deployments"/>

    <path id="lib.classpath">
      <fileset dir="${client.basedir}">
          <include name="/lib/*.jar"/>
          <!-- <exclude name="jboss-servlet-api_3.0_spec-1.0.0.Final.jar" /> -->
      </fileset>
      <!-- <fileset dir="${client.basedir}/properties">
         <include name="*.properties"/>
     </fileset>
     <fileset dir="${server.dir}/dist">
         <include name="*.jar"/>
     </fileset>
     <fileset dir="${client.basedir}/WEB-INF/lib">
         <include name="*.jar"/>
     </fileset> -->
    </path>
    <path id="server.classpath">
      <fileset dir="${server.dir}/dist">
          <include name="*.jar"/>
      </fileset>
    </path>
    <path id="mf.classpath">
        <path refid="${lib.classpath}"/>
        <path refid="${server.classpath}"/>
    </path>
    <path id="war.classpath">
      <fileset dir="${client.basedir}/WEB-INF/lib">
          <include name="*.jar"/>
      </fileset>
    </path>
  <target name="client.init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${client.build}"/>
    <mkdir dir="${client.dist}"/>
    <mkdir dir="${client.done}"/>
    <mkdir dir="${client.app}"/>
    <mkdir dir="${client.webinf_classes}"/>
    <mkdir dir="${client.webinf_classes}/grahamsprojclient/servlet"/>
  </target>
  <target name="client.compile" depends="client.init"
       description="compile the source " >
    <!-- Compile the java code from ${src} into ${dist} -->
    <javac srcdir="${client.src}" destdir="${client.dist}" >
        <classpath>
            <path refid="mf.classpath"/>
        </classpath>
    </javac>
  </target>
  <target name="client.package" depends="client.compile" description="create the jar">  
        <!-- <manifestclasspath property="manifest.path" jarfile="${dist}/GrahamsProjClient.jar">
           <classpath refid="mf.classpath"/>
       </manifestclasspath> -->
        <jar destfile="${client.app}/GrahamsProjClient.jar" basedir="${client.dist}" >
            <fileset dir="${client.basedir}/properties">
                <include name="*.properties"/>
            </fileset>
            <fileset dir="${client.basedir}">
                <include name="lib/*.jar"/>
                <!-- <exclude name="lib/jboss-servlet-api_3.0_spec-1.0.0.Final.jar" />-->
            </fileset>
            <manifest>
                <attribute name="Class-Path" value="${mf.classpath}"/>
                <attribute name="Main-Class" value="grahamsprojclient.main.Start"/>
            </manifest>
        </jar>
  </target>
  <!--<target name="deploy" depends="package"
       description="generate the distribution" >
   <ear destfile="${deploy.location}/GrahamsProjServer.ear" appxml="${client.basedir}/META-INF/application.xml" >
       <metainf dir="${client.basedir}/META-INF"/>
       <fileset dir="${dist}" includes="*.jar"/>
   </ear>
 </target> -->
  <target name="client.clean"
       description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${client.build}"/>
    <delete dir="${client.dist}"/>
    <delete dir="${client.app}"/>
    <delete dir="${client.done}"/>
    <delete dir="${client.webinf_classes}"/>
    <echo message="Deleting files in ${deploy.location}"/>
    <delete>
        <fileset dir="${deploy.location}" >
            <exclude name="*.txt" />
        </fileset>
    </delete>
  </target>
  <target name="client.compile-war-lib">
      <mkdir dir="WEB-INF/classes"/>
      <javac srcdir="${client.src}" destdir="WEB-INF/classes" debug="true" includeAntRuntime="false">
          <classpath refid="war.class.path"/>
          <include name="**/*.java"/>
      </javac>
  </target>
  <target name="client.compile-war" depends="client.init" description="compile the source " >
    <!-- Compile the java code from ${src} into ${dist} -->
    <javac srcdir="${client.basedir}/src/grahamsprojclient/servlet"
          destdir="${client.basedir}/WEB-INF/classes/grahamsprojclient/servlet" >
        <classpath>
            <path refid="war.class.path"/>
        </classpath>
    </javac>
  </target>

  <target name="client.build_war" depends="client.package, client.compile-war" description="build war" >  
      <war destfile="${client.done}/GrahamsProjClient.war" webxml="WEB-INF/web.xml">
        <metainf dir="${client.basedir}/META-INF" includes="context.xml" />
        <lib dir="${client.basedir}/WEB-INF/lib">
            <exclude name="/CopyLibs"/>
            <exclude name="*.ex" />
        </lib>
        <classes dir="${client.basedir}/WEB-INF/classes/grahamsprojclient/servlet" >
            <exclude name="*.java" />
        </classes>
        <fileset dir="${client.basedir}" >
            <include name="GrahamsProjClient-webstart.jnlp"/>
            <include name="app/GrahamsProjClient.jar"/>
            <include name="GrahamsProjStartAppPage.html"/>
            <!-- <include name="lib/*.jar"/>
           <include name="lib/jboss-servlet-api_3.0_spec-1.0.0.Final.jar"/> -->
        </fileset>
      </war>
  </target>
  <target name="client.deploy_war" depends="client.build_war" description="deploy war">
        <copy file="${client.done}/GrahamsProjClient.war" todir="${deploy.location}" />
  </target>
</project>

这是 ant 构建日志(底部的错误):

client.init:
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientbuild
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientdist
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientdone
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientapp
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientWEB-INFclasses
Created dir: C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientWEB-INFclassesgrahamsprojclientservlet
client.compile:
C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientbuild-client.xml:67: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
Compiling 6 source files to C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientdist
Unresolvable reference ${lib.classpath} might be a misuse of property expansion syntax.
C:UsersgbaldeckGoogle DriveWorkLearningAS7GrahamsProjClientbuild-client.xml:67: Reference ${lib.classpath} not found.
BUILD FAILED (total time: 0 seconds)

是什么原因导致这种情况发生?我认为我的路径设置方式没有任何问题。

您使用引用 ID lib.classpathserver.classpath 定义了路径,但是当您引用它们时:

<path id="mf.classpath">
    <path refid="${lib.classpath}"/>
    <path refid="${server.classpath}"/>
</path>

您正在将它们视为尚未定义的属性。 你可能的意思是:

<path id="mf.classpath">
    <path refid="lib.classpath"/>
    <path refid="server.classpath"/>
</path>

我认为您在第 67 行使用 ${lib.classpath},但您没有定义它。

相关内容

最新更新