What is the best practice for including third party jar files in a Java program?

Posted by ZoFreX on Stack Overflow See other posts from Stack Overflow or by ZoFreX
Published on 2010-03-13T03:35:01Z Indexed on 2010/03/13 3:37 UTC
Read the original article Hit count: 247

Filed under:
|
|
|
|

I have a program that needs several third-party libraries, and at the moment it is packaged like so:

zerobot.jar (my file)
libs/pircbot.jar
libs/mysql-connector-java-5.1.10-bin.jar
libs/c3p0-0.9.1.2.jar

As far as I know the "best" way to handle third-party libs is to put them on the classpath in the manifest of my jar file, which will work cross-platform, won't slow down launch (which bundling them might) and doesn't run into legal issues (which repackaging might).

The problem is for users who supply the third party libraries themselves (example use case, upgrading them to fix a bug). Two of the libraries have the version number in the file, which adds hassle.

My current solution is that my program has a bootstrapping process which makes a new classloader and instantiates the program proper using it. This custom classloader adds all .jar files in lib/ to its classpath.

My current way works fine, but I now have two custom classloaders in my application and a recent change to the code has caused issues that are difficult to debug, so if there is a better way I'd like to remove this complexity. It also seems like over-engineering for what I'm sure is a very common situation.

So my question is, how should I be doing this?

© Stack Overflow or respective owner

Related posts about java

Related posts about jar