How to build an executable jar file with Ant

筅森魡賤 提交于 2019-12-24 04:09:25

问题


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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/5959463/how-to-build-an-executable-jar-file-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!