Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, multiple jars or one large?

Tags:

java

As far as efficiency and memory usage goes, is it better to have one large jar with a class/package for each feature as needed? Or is it instead better to separate it out into smaller more-manageable jars?

Lets say I have a large project with 20-30 packages all unrelated to each other:

com.example.test
   - class 1
   - class 2
   - class 3
   - another.package
      - class 1
      - class 2
      - class 3
   - another.package
      - class 1
      - class 2
      - class 3
   - another.package
      - class 1
      - class 2
      - class 3

Would it instead be more efficient to split up each package into its own jar? And have multiple, smaller more lightweight jars? Im not sure if this even matters, however i am curious as it would make further development easier if i split everything up a bit. (as long as there is no performance disadvantages)

like image 850
ThatGuy343 Avatar asked Dec 26 '14 22:12

ThatGuy343


1 Answers

If the packages are unrelated, then they shouldn't be in the same jar, period.

By splitting up the jar, users could choose which packages they need in deployment, and include only those nothing more.

You want to deploy the minimal possible code. Anything extra is an additional potential problem, bug, security hole. Unnecessary stuff could also slow down the class loader, though that's a tiny concern compared to the others I mentioned earlier.

If some of them, or all of them, are always used together, then for practical reasons it can be ok to bundle them together.

like image 103
janos Avatar answered Oct 08 '22 22:10

janos