How to use shared libraries for multiple Java web projects

I have four different projects, and I use Weblogic to deploy my projects. There are several libraries (jar files) that are common to all projects. Currently, each of my projects has a lib directory and has almost the same set of libraries. Now, is it possible to have this lib directory outside of WAR files and access them.

+6
java java-ee weblogic
source share
7 answers

Resist the temptation to put jar files in the β€œshared” folder of your container. It is better to store jar files where they are. It might seem like 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.

Saying, I have no experience with WebLogic. Tomcat has a shared folder with libraries that are common to all deployed applications. It is not recommended to use this. If WebLogic can be configured to use a shared folder for a set of applications (and not for all deployed applications), you can go for it.

+8
source share

Do you want to do this? If you were not stuck in the deployment space, I would (maybe) advise him.

Why? At the moment, you have 4 solutions running these libraries. If you need to update one of the libraries (say, if you find an error or you need a new function), you will have to test compatibility and functionality for all 4 solutions. If each solution has its own set of libs, then they are isolated and you do not need to move all 4 steps.

Please note that it all depends on how easy it is to regressively test your solutions. It may be easy for you, and in this case it is possible to use the same set of libraries.

+3
source share

Do not do this.

The whole idea of ​​WAR files is that they are standalone devices. This simplifies deployment.

In addition to the possible version conflicts that others have indicated, placing jar files in / shared can have very nested effects on class visibility. They will be located on a separate classloader and will not be able to see the classes in the WAR file. If you use libraries that rely on Class.forName () to work (and there are many), this can be very painful.

If you really really can't afford the extra disk space and memory, take a look at OSGi or Spring DM. They solved this problem, but at the price of increased complexity.

+2
source share

Put all the common jar files in the \ lib weblogic shared folder. common \ lib is available for all deployed applications.

+1
source share

Well, first of all, you can place your libraries in the same place and import the assemblies they need.

For deployment, the new Weblogic 10 has a lib folder in each domain where you can put shared libraries. I don't think this is possible until Weblogic 10

0
source share

You can put the cans in your own ear file and deploy it as a shared library.

You can also put wars in your ear and add common cans to APP-INF / lib. This is a Weblogic J2EE extension, so it will not work on other servers.

0
source share

I am currently using a different approach.

  • Create a central repository folder and place all the common libraries there.
  • In each project, you can create a link to all the necessary libraries. In Subversion, it works with externals

Each time, the local working copy is updated, external elements are updated, so you just need to fix the central folder and automatically distribute it across all projects.

-one
source share

All Articles