简体   繁体   English

如何使用Ant构建可执行的jar文件

[英]How to build an executable jar file with Ant

I'm developing Swing based application in Java I want a executable JAR file for this project. 我正在用Java开发基于Swing的应用程序,我想要该项目的可执行JAR文件。

All external library files used in the project should be packaged in the JAR file. 项目中使用的所有外部库文件都应打包在JAR文件中。

How can I build a runnable JAR file using ANT? 如何使用ANT构建可运行的JAR文件?

but it needs all external library files used in the project should be along with the jar. 但它需要项目中使用的所有外部库文件都应与jar一起使用。

Of course, but the external JARS should not be bundled in with the executable JAR. 当然,但是外部JARS不应与可执行JAR捆绑在一起。

You need to do three things: 您需要做三件事:

  1. Create a manifest for your executable JAR that specifies the Main-Class. 为您的可执行JAR创建一个清单,该清单指定Main-Class。
  2. Add the CLASSPATH to you manifest that spells out the location of each and every dependent JAR relative to the executable JAR. 将CLASSPATH添加到您的清单中,以阐明每个相关JAR相对于可执行JAR的位置。
  3. Create a ZIP file that contains the executable JAR and all the dependent JARs, with paths relative to the executable JAR as specified in your manifest. 创建一个包含可执行JAR和所有从属JAR的ZIP文件,并在清单中指定相对于可执行JAR的路径。

You give clients the ZIP. 您给客户邮递区号。 They unpack it and execute your executable JAR. 他们解压缩并执行您的可执行JAR。

You need to include the manifest task in your jar task. 您需要将manifest任务包括在jar任务中。 The manifest references the main class to be executed by default when you start your jar. 清单在启动jar时引用要默认执行的主类。

it could look like this : 它可能看起来像这样:

<jar...
<manifest file="MANIFEST.MF">
    <attribute name="Main-Class" value="com.example.YourMainClass"/>
</manifest>
</jar>

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

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