Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share .jar files between Java Applications

Tags:

java

jar

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.

like image 577
Ram Avatar asked Jun 22 '26 20:06

Ram


2 Answers

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).

like image 133
peter.petrov Avatar answered Jun 25 '26 09:06

peter.petrov


There are a few options:

  1. You can use something like Maven, which will manage the JAR files for you.

  2. You can create a library folder and reference this to the projects you've got.

  3. If you're using Eclipse, you can create shared user libraries (read more here).

Hope this helps!

like image 30
priboyd Avatar answered Jun 25 '26 10:06

priboyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!