简体   繁体   中英

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.

All external library files used in the project should be packaged in the JAR file.

How can I build a runnable JAR file using ANT?

but it needs all external library files used in the project should be along with the jar.

Of course, but the external JARS should not be bundled in with the executable JAR.

You need to do three things:

  1. Create a manifest for your executable JAR that specifies the 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.
  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.

You give clients the ZIP. They unpack it and execute your executable JAR.

You need to include the manifest task in your jar task. The manifest references the main class to be executed by default when you start your jar.

it could look like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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