有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java的目标是从我的项目中删除不起作用的文件

我有一个示例项目和一个文件build.xml,它定义了某些目标来组装该目标

构建。xml

    <project name="JavaProject" default="doLab1" basedir=".">  
      <property name="app.name" value="JavaProject" />    
      <property name="app.version" value="1.0" />
      <property name="app.title" value="Sample of Title" />
      <property name="app.author" value="Artem Sevruk" />
      <property name="app.company" value="Suicidal DevCo" />

      <property name="sourceDir" value="src/main/java" />
      <property name="outputDir" value="out/eclipse-classes" />
      <property name="buildDir" value="out/build" />
      <property name="resourceDir" value="src/res" />
      <property name="libDir" value="lib" />

      <property name="jar.mainClass" value="com.lab111.TestMain" />
      <property name="jar.name" value="${app.name}.jar" />
      <property name="jar.keyStore" value="${basedir}/out/tempKey.store" />
      <property name="jar.keyPass" value="telpat" />
      <property name="jar.keyAlias" value="tempAlias" />

       <property name="compile.debug"       value="true"/>
       <property name="compile.deprecation" value="false"/>
       <property name="compile.optimize"    value="true"/>
       <path id="compile.classpath">
          <fileset dir="${libDir}">
            <include name="*.jar"/>
        </fileset>
       </path>

        <target name="prepare"
                description="Prepare build dirs">
          <mkdir  dir="${buildDir}"/>
          <mkdir  dir="${buildDir}/output"/>
          <mkdir  dir="${buildDir}/web-apps"/>
        </target>

        <target name="compile" 
                depends="prepare"
                description="Compile Java sources">

          <javac srcdir="${sourceDir}"
                destdir="${buildDir}/output"
                  debug="${compile.debug}"
            deprecation="${compile.deprecation}"
               optimize="${compile.optimize}"
                 target="1.8"
                 source="1.8"
            includeantruntime="false">
              <classpath refid="compile.classpath"/>
          </javac>

          <copy  todir="${buildDir}/output">
            <fileset dir="${sourceDir}" excludes="**/*.java"/>
          </copy>
        </target>

        <target name="createJAR" 
                depends="compile"
                description="Create JAR archive" >
            <jar destfile="${buildDir}/${jar.name}" basedir="${outputDir}">
                  <manifest>
                    <attribute name="Created-By" value="${app.author} - (${app.company})"/>
                    <attribute name="Built-By" value="${user.name}"/>
                    <attribute name="Main-Class" value="${jar.mainClass}"/>
                    <section name="${app.name}">                  
                      <attribute name="Specification-Title" value="${app.title}"/>
                      <attribute name="Specification-Version" value="${app.version}"/>
                      <attribute name="Specification-Vendor" value="${app.company}"/>
                      <attribute name="Implementation-Title" value="${app.name}"/>
                      <attribute name="Implementation-Version" value="${app.version}"/> 
                      <attribute name="Implementation-Vendor" value="${app.company}"/>
                    </section>
                  </manifest>           
            </jar>
        </target>


        <target name="signJAR" 
                depends="createJAR"
                description="Signing JAR archive">
            <exec dir="${buildDir}" executable="jarsigner">
              <arg line="-keystore ${jar.keyStore} -storepass ${jar.keyPass} ${jar.name} ${jar.keyAlias}"/>
            </exec>
            <delete file="${buildDir}/myKeystore" />
        </target>
    </project>

我的任务是删除所有带有扩展名的文件。罐子tmp。从目录中初始化,但名称以“a”开头的除外。 我这样写道:

<target name="doLab1" depends="signJAR"
        description="Delete .jar, .tmp, .class files except first 'a' in name">
        <delete>
            <fileset dir="." includes="**/*.jar" excludes="**/a*.jar"/>
            <fileset dir="." includes="**/*.tmp" excludes="**/a*.tmp"/>
            <fileset dir="." includes="**/*.class" excludes="**/a*.class"/>
        </delete>
    </target>

我通过创建具有适当名称的文件来测试它是否有效,但它不会删除任何文件。 there r no info under doLab1


共 (1) 个答案

  1. # 1 楼答案

    它工作完美,没有任何问题。我有两个罐子,一个是ast。另一个是测试。罐子

    Apache Ant(TM) version 1.9.4 compiled on April 29 2014
    Buildfile: c:\temp\build.xml
    Detected Java version: 1.8 in: C:\Program Files\Java\jre1.8.0_162
    Detected OS: Windows 7
    parsing buildfile c:\temp\build.xml with URI = file:/c:/temp/build.xml
    Project base dir set to: c:\temp
    parsing buildfile jar:file:/C:/Software/Apache%20ANT%201.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/Software/Apache%20ANT%201.9.4/lib/ant.ja
    Build sequence for target(s) `doLab1' is [doLab1]
    Complete build sequence is [doLab1, ]
    
    doLab1:
       [delete] Deleting c:\temp\anttest\test.jar
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    

    这是建造。xml

    <project>
    <property name="delDir" value="c:/temp/anttest" />
    <target name="doLab1"
        description="Delete .jar, .tmp, .class files except first 'a' in name">
        <delete>
            <fileset dir="${delDir}" includes="**/*.jar" excludes="**/a*.jar"/>
            <fileset dir="${delDir}" includes="**/*.tmp" excludes="**/a*.tmp"/>
            <fileset dir="${delDir}" includes="**/*.class" excludes="**/a*.class"/>
        </delete>
    </target>
    
    </project>
    

    使用的命令是

    ant doLab1 -v -f c:\temp\build.xml