Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use common libraries for multiple Java web project

I am having four different project, and i am using Weblogic to deploy my projects. There are several libraries ( jar files ) which are common for all projects. Currently each of my project are having lib directory and have almost same set of libraries. Now, is it possible to have this lib directory outside WAR files and access them.

like image 780
Rakesh Juyal Avatar asked Jun 30 '09 09:06

Rakesh Juyal


People also ask

How do I add a library to a Java project?

Right-click the Java project to which you want to add a library, and select Properties from the menu. Select Java Build Path, and click the Libraries tab. Click the Add Library button, and choose the appropriate Java EE Library. Click Next to view the library contents, and click Finish.

How do you use libraries in Java?

To use a library, you have to add it to your classpath, which you pass into the javac and java commands using the -cp argument. As long as you do that, you can use classes from a library exactly like you can use a regular Java class or a class that you create- they're all just Java classes.

What is shared library in Java?

Shared libraries are compiled for the actual ISA of the mobile so they do not need any VM to run. They are added into to apk file as they are.


2 Answers

Resist the temptation of putting the jar files in the "shared" folder of your container. It is better to keep the jar files where they are now. It may sound a good idea to use a shared folder now, but in the future you may need to deploy an application that requires a shared library, but a different version.

That being said, I have no experience with WebLogic. In Tomcat there is a shared folder with libraries common for all deployed applications. It is not a good idea to use this. If WebLogic can be configured to use a shared folder per a set of applications (and not for all deployed applications) you could go for it.

like image 174
kgiannakakis Avatar answered Sep 19 '22 12:09

kgiannakakis


Do you want to do this ? Unless you're stuck for deployment space, I would (perhaps) advise against it.

Why ? At the moment you have 4 solutions running off these libs. If you have to upgrade one of the libs (say, if you discover a bug, or if you require a new feature), then you're going to have to test compatibility and functionality for all 4 solutions. If each solution has its own set of libs, then they're sandboxed and you don't have to move all 4 in step.

Note that all this hinges on how easy it is to regression-test your solutions. You may find it easy, in which case using the same set of libs is feasible.

like image 29
Brian Agnew Avatar answered Sep 19 '22 12:09

Brian Agnew