English 中文(简体)
一项任务,即过滤JAR,以备齐和显示
原标题:Ant task to filter JARs for zip file and manifest
  • 时间:2012-05-01 12:36:59
  •  标签:
  • java
  • ant
  • jar

我有一份Ant案,我在那里正在编造一个齐普案卷和几个JAR档案的明证。 斜坡和明显参照的是相同的图书馆,但略有不同。 如果可能的话,我想把提及档案的内容合并起来,而不是明确地写两篇,而同时在这两个任务中引用这些文件。 以下是我目前所做工作的例子。

<target name="zip" depends="default">
  <zip destfile="${dist.dir}/${project.name}_v${project.version}.zip">
    <zipfileset prefix="lib" dir="lib/Dom4J" includes="*.jar"/>
    <zipfileset prefix="lib" dir="lib/GSON" includes="*.jar"/>
    <zipfileset prefix="lib" dir="lib/Guava" includes="*.jar"/>
    <!-- ... A bunch more (Note I don t want everything 
             in the lib directory, just certain subfolders 
             within the lib directory which are explicitly 
             listed here like GSON. -->
    </zip>
</target>

<target name="createManifest">
   <!-- Hard code the classpath by hand and hope 
        they sync up with the zip task -->
   <property name="mfClasspath" 
             value="dom4j-1.6.1.jar gson-2.1.jar guava-11.0.2.jar" />
   <!-- Code to use the mfClasspath when creating the manifest 
        omitted for brevity -->
</target>

理想的情况是,我可在这两项任务中参考的某种类型的<代码>>>。 注:该清单不含任何文件夹/带。 该清单仅载有在<代码>zip任务中提及的名录内发现的JAR档案。

最佳回答

You are right. You can accomplish this with a common fileset shared by both the zip and createManifest tasks. For the zip task, copy the files to a temporary location and then zip them up.

关于<代码>createManifest的任务,使用特性替代物,将文件夹从中删除。 特征-替代战略在“,则您可使用 rel=“nofollow noreferer”简化下文的特性-替代算法。 不动产 页: 1

<project default="all">
    <fileset id="jars" dir=".">
        <include name="lib/Dom4J/dom4j-1.6.1.jar" />
        <include name="lib/GSON/gson-2.1.jar" />
        <include name="lib/Guava/guava-11.0.2.jar" />
    </fileset>

    <target name="zip">
        <copy todir="tmp.dir" flatten="true">
            <fileset refid="jars" />
        </copy>
        <zip destfile="example.zip">
            <zipfileset dir="tmp.dir" prefix="lib" />
        </zip>
        <delete dir="tmp.dir" />
    </target>

    <target name="createManifest">
        <property name="jars.property" refid="jars" />
        <echo message="${jars.property}" file="some.tmp.file" />
        <loadfile property="mfClasspath" srcFile="some.tmp.file">
            <filterchain>
                <tokenfilter>
                    <replaceregex pattern="(?:[^;/]+/)+?([^;/]+.jar)"
                        replace="1" flags="g" />
                    <replacestring from=";" to=" " />
                </tokenfilter>
            </filterchain>
        </loadfile>
        <delete file="some.tmp.file" />
    </target>

    <target name="all" depends="zip, createManifest">
        <echo message="$${jars.property} = &quot;${jars.property}&quot;" />
        <echo message="$${mfClasspath} = &quot;${mfClasspath}&quot;" />
    </target>
</project>

当我执行上述安特建书时,以下是向奥塞罗省输出的:

Buildfile: /workspace/StackOverflow/build.xml
zip:
      [zip] Building zip: /workspace/StackOverflow/example.zip
   [delete] Deleting directory /workspace/StackOverflow/tmp.dir
createManifest:
   [delete] Deleting: /workspace/StackOverflow/some.tmp.file
all:
     [echo] ${jars.property} = "lib/Dom4J/dom4j-1.6.1.jar;lib/GSON/gson-2.1.jar;lib/Guava/guava-11.0.2.jar"
     [echo] ${mfClasspath} = "dom4j-1.6.1.jar gson-2.1.jar guava-11.0.2.jar"
BUILD SUCCESSFUL
Total time: 675 milliseconds

另外,example.zip 载有下列条目:

  • lib/dom4j-1.6.1.jar
  • lib/gson-2.1.jar
  • lib/guava-11.0.2.jar
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签