使用Ant构建jar文件时如何设置类路径顺序? [英] How to set classpath order while building jar file using Ant?

查看:84
本文介绍了使用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}" />

必须以某种默认顺序包含瓶子.我想更改此默认顺序.

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

关于我为什么要这样做的注释:我的Java桌面应用程序使用了许多包含在类路径中的第三方jar.当我通过Eclipse运行代码时,它可以正常工作.但是,当我使用ANT构建jar文件时,它无法按预期工作.我确定它与classpath中的jar序列有关,就像我在Eclipse中更改jar顺序一样,它也在那里失败.

A note on why I want this: my Java desktop application uses many third 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 Kepler,Java 7,Ant 1.8.

Note: I am using Eclipse Kepler, Java 7, Ant 1.8.

推荐答案

最后,我得到了解决方案.我在更改ANT文件后构建了Jar.现在,我的ANT版本在classpath中显式包含了第三方API,这是解决方案的关键.

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>

以前,我在ANT中有如下的类路径条目:

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

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

这篇关于使用Ant构建jar文件时如何设置类路径顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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