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

标签 java xml build

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

build.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>

我的任务是从目录中删除所有扩展名为 .jar、.tmp、.class 的文件,但名称以 '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

最佳答案

它运行完美,没有任何问题。我有两个 jar ,一个是 ast.jar,另一个是 test.jar

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

这是build.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

关于java - 目标是从我的项目中删除文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52371212/

相关文章:

JavaFX 自定义标题栏

java - 在 Android 中从内存中加载声音

objective-c - NSXMLParser 仅从提要中获取最后一个对象

c++ - 我应该将 CMakeList.txt 从源文件夹中分离出来吗?

Android: build.properties 排除

java - 存储包含多种字符的字符串

java - 获取 Object[][] 数组的子长度

azure - Azure DevOps 中的 Cypress 自动化项目

xml - Xpath 通过将基本 URL 与从 Xml 获得的字符串组合来获取完整 URL

java - 关于属性的先验知识?