Java Libraries – Is Including Extra Libraries in JARs a Good Idea?

javalibraries

When creating executable jars for a java project, it is possible to create jar bundle which includes all the external libraries used. It is also possible to create a jar without those external dependencies and provide the dependency path on run-time instead.

What I am wondering is which one is better? Is there a favorable way of doing it?

Best Answer

It depends.

You need to think about how your product will be used by consumers. For example, if you are creating a library that will be used by others inside Maven, then you should not include the external dependencies in the jar - let Maven handle it by providing a proper pom.

However, if instead you are deploying a completed application for non-technical users, then you absolutely do want to keep everything as simple as possible for them, and you should provide the dependencies inside the Jar.

In short, think about who your users are and what their use case would be, and then decide accordingly.