你如何使用Ant其unjar多个JAR文件,并将其重建成一个JAR文件? [英] How do you use ant to unjar multiple JAR files and rebuild them into one JAR file?

查看:271
本文介绍了你如何使用Ant其unjar多个JAR文件,并将其重建成一个JAR文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将其unjar多个JAR文件,然后使用Ant构建脚本重新构建成一个JAR。这可能吗?

I would like to unjar multiple JAR files and then rebuild into one JAR using an ant build script. Is this possible?

推荐答案

是的,这可能与蚂蚁。一个jar文件基本上是一个特殊的清单文件的zip。所以不能解压缩,我们需要解压的罐子。蚂蚁包括解压任务。

Yes, it's possible with ant. A jar file is basically a zip with a special manifest file. So to unjar, we need to unzip the jars. Ant includes an unzip task.

要解压缩/不能解压缩的所有项目中的jar文件:

To unzip/unjar all the jar files in your project:

<target name="unjar_dependencies" depends="clean">
    <unzip dest="${build.dir}">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
        </fileset>    
    </unzip>
</target>

显然,你需要声明$ {build.dir}和$ {} lib.dir第一。行&LT;包括姓名=** / *罐子。/&GT; 告诉Ant包括结束与罐子扩展名的文件,你可以调整,包括满足您的需求。

Obviously you need to declare ${build.dir} and ${lib.dir} first. The line <include name="**/*.jar" /> tells ant to include all files that end up with the jar extension, you can tweak that include to suit your needs.

要收拾一切都变成一个罐子,你可以使用罐子任务:

To pack everything into a jar, you use the jar task:

<target name="make_jar" depends="compile, unjar_dependencies">
    <jar basedir="${build.dir}"
         destfile="${dist.dir}/${project_name}.jar">
        <manifest>
            <attribute name="Main-Class" value="${mainclass}" />
        </manifest>
        <fileset dir="${build.dir}">
            <include name="**/*.class" />
        </fileset>
        <fileset dir="${src.dir}">
            <include name="applicationContext.xml" />
            <include name="log4j.properties" />
        </fileset>
    </jar>
</target>

在这个例子中,我们有不同的文件集。在一个文件集,我们包括所有编译的类。在另一个文件集,我们包括两个配置文件,这个特殊的项目取决于

In this example, we include different filesets. In one fileset we are including all compiled classes. In another fileset we include two config files that this particular project depends upon.

这篇关于你如何使用Ant其unjar多个JAR文件,并将其重建成一个JAR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆