开发者

how to distribute a java-application with libraries such as itext?

I have written an application in java. It uses iText, jXL and JAI.

How do I build a jar which contains all these libraries? Or do I have to f开发者_Python百科orce the user to install these too?


Either unpack the jars into your jar, or just add them to the jar classpath via the Class-Path attribute in your meta-inf, and distribute the libraries along with your main jar. Sample META_INF/Manifest.mf:

Manifest-Version: 1.0
Class-Path: itext.jar jxl.jar jai.jar
Main-Class: com.xxx.yyy.Main


As soon as you're dealing with external libraries, you should have a look at Maven. This tool is a builder such as Ant, but it is able to handle library dependencies automatically. With this builder, you'll be able to both embed your project's dependencies in your jar and also to allow users to build it on their own computer without downloading library dependencies manually.

Here is the project's website: http://maven.apache.org/
where you can find quick how-tos: http://maven.apache.org/users/index.html
and finally eBooks to go further: http://maven.apache.org/articles.html


You could pack all jars into one while building your project with Ant. If you use NetBeans, This page describes how can modify NetBeans' build scripts to do it for you.


You could use an utility like jarjar to merge your classes and the other libraries into a single deployable file.


Thanks for all solutions!

Fatjar is a great plugin for Eclipse that does all this too (:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜