2

I am currently working in a Java project, and we use maven to build the final jar. There are two ways to build the jars as we all know, i.e. one single jar with-dependencies, and a jar without dependencies. In the latter case, we need to add dependent jars to the classpath as well.

In principle both can work, personally I prefer one jar with dependencies, but in the project team members decided to use separate jar without dependencies. So hereby I would like to know which choice is better?

Rui
  • 3,454
  • 6
  • 37
  • 70

1 Answers1

6

This question has no answer, since it depends on what you need to do.

If you're writing an utility package or component, that could be a dependency of another project, then there's no point in having all the dependencies inside it - it's better to leave dependency resolution to a dependency manager, like Maven.

If you, instead, are writing a full application packaged as a jar, I mean something with a MainClass that can be executed with java -jar myjar, then having the dependencies together will make distribution easier.

Consider that, for instance, if you're writing a webapp, that'll be packaged as a WAR, it normally comes with dependencies.

watery
  • 5,026
  • 9
  • 52
  • 92