ant、jar 文件和 Class-Path 哦,我的 [英] ant, jar files, and Class-Path oh my

查看:30
本文介绍了ant、jar 文件和 Class-Path 哦,我的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新构建我的构建技术,以创建依赖于常见 3rd 方 jar 文件的 Java jar 文件.(GlazedLists、Apache Commons 等)

I am trying to rearchitect my build technique for creating Java jar files which depend on common 3rd party jar files. (GlazedLists, Apache Commons, etc.)

我一直将它们全部放入 {Java JRE dir}/lib/ext,以便 JRE 自动看到它们,但这导致了诸如忘记我需要分发某些 jar 文件之类的问题,所以我会喜欢学习更明确.

I had been chucking them all into {Java JRE dir}/lib/ext so they would automatically be seen by the JRE, but that led to problems like not remembering that I need to distribute certain jar files, so I'd like to learn to be more explicit.

所以我将它们全部移到 c:\appl\java\common\,将它们添加到 Eclipse 构建路径,并在我的 ant 文件中定义:

So I moved them all into c:\appl\java\common\, added them to the Eclipse build path, aand defined this in my ant file:

<path id="javac_classpath">
    <fileset dir="${libDir}">
        <include name="*.jar"/>
    </fileset>
    <fileset dir="c:/appl/java/common">
        <include name="*.jar"/>
    </fileset>
</path>

我的 Class-Path 清单标头设置为."在我的 jar 任务中,但即使我将相关的 jar 文件放入与我的应用程序 jar 文件相同的目录中,这似乎也不起作用.我可以将它们全部手动一一添加到 Class-Path 标头中,但我想知道是否有更简单的方法来正确设置 Class-Path 标头?

I have my Class-Path manifest header set to "." in my jar task but that doesn't seem to work even if I put the relevant jar files into the same directory as my application jar file. I can add them all manually one-by-one to the Class-Path header, but I'm wondering, is there an easier way to get the Class-Path header setup properly?

推荐答案

这就是你所需要的:

<path id="build-classpath">
    <fileset dir="${dist}/lib">
        <include name="*.jar"/>
    </fileset>
</path>
<manifestclasspath property="lib.list" jarfile="${dist}/lib/myprog.jar">
    <classpath refid="build-classpath"/>
</manifestclasspath>
<jar jarfile="${dist}/lib/myprog.jar"
     basedir="${build}"
     includes="com/my/prog/**" >
    <manifest>
        <attribute name="Main-Class" value="com.my.prog.MyProg"/>
        <attribute name="Class-Path" value="${lib.list}"/>
    </manifest>
</jar>

正如您可能看到的,它假定您已经编译了 Java 类并将它们输出到 ${build}.它还假设您已将 jarfile 复制到 ${dist}/lib.

As you can probably see, it assumes you've compiled your Java classes and output them to ${build}. It also assumes you've copied your jarfiles to ${dist}/lib.

也就是说,值得研究其他内置支持依赖项的构建系统,例如 Maven 和 Gradle.这些其他构建系统已经考虑了许多常见的项目结构和构建操作,因此您不必将所有内容都编写到最后的细节中.

That said, it would be worth looking into other build systems which have built-in support for dependencies, such as Maven and Gradle. These other build systems have already thought through many common project structures and build operations, so you don't have to script everything down to the last detail.

这篇关于ant、jar 文件和 Class-Path 哦,我的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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