如何设置classpath中以便在使用ANT构建jar文件 [英] How to set classpath order while building jar file using ANT

查看:239
本文介绍了如何设置classpath中以便在使用ANT构建jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用zipgroupfileset捆绑从lib文件夹中的所有jar文件在我的可执行应用程序的jar文件,包括

I am using zipgroupfileset to bundle all jars from lib folder to include in my executable application jar file.

<zipgroupfileset dir="${lib.dir}" />

JAR必须得到包括在一些默认顺序。我想改变这种默认顺序。请指引我。

Jars must be getting included in some default order. I want to alter this default order. Please guide me.

为什么呢?
我的Java桌面应用程序使用,它们包含在类路径中的许多第三方罐。当我通过Eclipse中运行我的code正常工作。但是,当我使用Ant构建jar文件如预期这是行不通的。我相信,如果我在eclipse改变罐子以便它关系到罐子序列中的类路径中失败有作为。

Why? My java desktop application uses many 3rd party jars which are included in class path. When I run my code through eclipse it works fine. But when I build the jar file using ANT it doesn't work as expected. I am sure it is related to jar sequence in classpath as if I change jar order in eclipse it fails there as well.

请注意:我使用的Eclipse开普勒的Java 7,蚂蚁1.8

Note: I am using eclipse kepler, java 7, ant 1.8.

推荐答案

我终于得到了解决。我建立了我的改变ANT文件后,罐。现在我的ANT构建包括第三方的API明确CLASSPATH中,并且是关键的解决方案。

Finally I got the solution. I build the Jar after altering my ANT file. Now my ANT build includes 3rd party APIs explicitly in classpath and that was the key to the solution.

<property name="lib.dir" value="lib" />

<manifestclasspath property="jar.classpath" jarfile="${lib.dir}/*.jar">
    <classpath refid="project.class.path"/>
</manifestclasspath>

<jar destfile="${jar.dir}/${jar.name}">
        <fileset dir="${class.root}" includes="**/*.*" />
        <manifest>
                <attribute name="Main-Class" value="${Main-Class}" />
                <attribute name="Class-Path" value="${jar.classpath}" />
        </manifest>
</jar>

previously我在ANT类路径条目如下:

Previously I had class-path entry in ANT as follows:

<attribute name="Class-Path" value="." />

让我知道,如果有人想进一步澄清。

Let me know if someone wants more clarification.

这篇关于如何设置classpath中以便在使用ANT构建jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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