How to share .jar files between Java Applications

jar, java

Solution

If the two apps are on the same machine, you can put/deploy the jars in one folder. Then both apps can pick/load the jars at runtime from that shared folder. This is doable.

Say your folder is: `/some/folder/`

And the jars there are `a.jar` `b.jar` `c.jar`

Then just add

`/some/folder/a.jar` `/some/folder/b.jar` `/some/folder/c.jar`

to the classpaths of both apps (in the two apps' startup scripts).

But there's no one single pre-defined place on OS level to put those into (like `\Windows\System32` let's say) so that all Java apps on that machine pick their jars from there. And I find this a very good thing. So things are not quite the same as with DLLs (the example you give).

Problem

We have a suit of application which have some common .Jar files. While installing each app these files are copied to each application's folder. This results in wastage of storage space and also it is tedious to keep the files in sync. Does java provide any way to share .jars? Like in windows we can copy .dll file in \windows\system32 and it is available to all apps.

Original source