简体   繁体   English

我如何使用Ant来构建单个可执行文件.jar,该文件在.jar的/ lib目录中具有依赖项.jars?

[英]How can I use Ant to build a single executable .jar that has dependency .jars in it in a /lib dir in the .jar?

How can I use Ant to build a single executable .jar that has dependency .jars in it in a /lib dir in the . 我如何使用Ant来构建单个可执行文件.jar ,该文件在.lib的/lib目录中具有依赖项.jars。 jar ? 罐子

I have a /lib directory in the project root file that contains all the binary dependency .jar s. 我在项目根文件中有一个/lib目录,其中包含所有二进制依赖项.jar

In java an executable jar has a specially formatted manifest , that includes the following attributes: 在Java中,可执行jar具有特殊格式的清单 ,其中包括以下属性:

  1. Main-Class 主类
  2. Class-Path 类路径

In ANT this is easily accomplished as follows with the jar task: 在ANT中,可以通过jar任务轻松完成此操作:

<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="*.class">
    <manifest>
        <attribute name="Main-Class" value="${main-class}" />
        <attribute name="Class-Path" value="${jar-classpath}" />
    </manifest>
</jar>

For extra credit one can use the very useful manifestclasspath task to help assemble the correct classpath string. 为了获得额外的荣誉,可以使用非常有用的manifestclasspath任务来帮助组装正确的classpath字符串。

<manifestclasspath property="jar-classpath" jarfile="${jar.dir}/${ant.project.name}.jar">
    <classpath>
        <fileset dir="/path/to/lib/dir" includes="*.jar"/>
    </classpath>
</manifestclasspath>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM