Ant 在 dest jar 中包含 jar 文件和 .class 文件 [英] Ant including both jar files and .class files in dest jar

查看:42
本文介绍了Ant 在 dest jar 中包含 jar 文件和 .class 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 ant build.xml 定义了一个 jar 任务.我需要将所有依赖项捆绑到我的 jar 中.我不明白为什么 ant 会提取 jar 并将 .jars 和 .class 文件都包含到我的 jar 中.它不必要地增加了我的 jar 文件的大小.这是我的 jar 任务.

I have defined a jar task using ant build.xml. I need to bundle all the dependencies into my jar. I don't understant why ant extracts the jars and includes both .jars and .class files into my jar. It unnecessarily increases the size of my jar file. Here is my jar task.

<jar destfile="build/main/ERS2SupportingUtilities.jar">
            
            <fileset dir="target/classes">
                <exclude name="*.sh"/>
            </fileset>

            <restrict>
             <name name="**/*.class"/>
             <archives>
               <zips>
                 <fileset dir="./src/main/resources/lib" includes="**/*.jar"/> 
               </zips>
             </archives>
            </restrict>

            <manifest>
              <attribute name="Main-Class" value="com.cibc.ers2.invoker.JobTest"/>
                <attribute name="Class-Path" value="./lib/log4j-1.2.16.jar
                                                    ./lib/org.springframework.context-3.0.3RELEASE.jar
                                                    ./lib/org.springframework.asm-3.0.3.RELEASE.jar
                                                    ./lib/junit-4.7.jar
                                                    ./lib/org.springframework.orm-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.transaction-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.aspects-3.0.3.RELEASE.jar
                                                    ./lib/commons-pool-1.5.4.jar
                                                    ./lib/org.springframework.core-3.0.3.RELEASE.jar
                                                    ./lib/commons-logging-1.1.1.jar
                                                    ./lib/HashUtility.jar
                                                    ./lib/org.springframework.expression-3.0.3.RELEASE.jar
                                                    ./lib/commons-lang-2.6.jar
                                                    ./lib/org.springframework.instrument-3.0.3.RELEASE.jar
                                                    ./lib/mockito-all-1.9.5.jar
                                                    ./lib/com.springsource.org.aopalliance-1.0.0.jar
                                                    ./lib/ojdbc14.jar
                                                    ./lib/commons-io-2.4.jar
                                                    ./lib/commons-collections-3.1.jar
                                                    ./lib/org.springframework.jdbc-3.0.3.RELEASE.jar
                                                    ./lib/spring-batch-infrastructure-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.context.support-3.0.3.RELEASE.jar
                                                    ./lib/commons-dbcp-1.4.jar
                                                    ./lib/spring-batch-test-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.beans-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.oxm-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.aop-3.0.3.RELEASE.jar
                                                    ./lib/commons-beanutils.jar
                                                    ./lib/org.springframework.binding-2.1.1.RELEASE.jar
                                                    ./lib/spring-batch-core-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.test-3.0.3.RELEASE.jar
                                                    ./launch-context.xml
                                                    ./log4j.xml"
                />
            </manifest>
        </jar>

我也试过 zipgroupfileset 但也有同样的问题.

I have also tried zipgroupfileset but that also is giving the same problem.

抱歉没有提供足够的信息来说明我正在努力实现的目标.我有一个应用程序,我正在编译 @target/classes.我需要将此应用程序(包括我的类文件和依赖项)打包到一个 jar 中.

Apologies for not giving enough info about what I am trying to achieve. I have got an application which I am compilint @ target/classes. I need to package this application including my class files and dependecies into one jar.

推荐答案

 <fileset dir="target/classes">
     <exclude name="*.sh"/>
 </fileset>

包括来自目标/类的所有文件,这些文件不是 shell 脚本.

includes all files from target/classes which are not shell scripts.

<restrict>
    <name name="**/*.class"/>
    <archives>
         <zips>
             <fileset dir="./src/main/resources/lib" includes="**/*.jar"/> 
          </zips>
     </archives>
</restrict>

您似乎再次在此处包含类和 jar.

It seems like you again include classes and jars here.

如果你只想要 jar 将以上所有更改为:

If you want only jar change all above to :

<zipfileset dir="./src/main/resources/lib" includes="*.jar"/>

这篇关于Ant 在 dest jar 中包含 jar 文件和 .class 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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