简体   繁体   中英

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 force 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.

您可以使用像jarjar这样的实用程序将您的类和其他库合并到一个可部署的文件中。

Thanks for all solutions!

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

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