The library is used to hold the artifacts of both Module A and B, in other words,is added as a dependency in both these projects. Ok, so far, everything seems fine. What happens when these two modules are deployed to the server (WebSphere Process Server)?Ever thought about it?Well, everytime we want to deploy an application on the server, we extract an .EAR (EAR is the extension of the file for eg:,ModuleA.ear. Don't read it as Ear, nose or mouth files :-)) file of that module and deploy it on the server. So let's see, what happens when we extract an EAR of the module?Yes, it does compress the module and it's artifacts into an .ear file but let's dig deeper and see what this ear file could contain in it.Have a look at the screenshot below:
Oh, so there's a .jar and .war versions of the module, which is ok. But look, the library is packaged with the module too!This is the case for ModuleA. Similarly, the library would be packaged with ModuleB too. Isn't that a redundancy?Think about every other module which uses this library.Isn't that a huge overhead and memory footprint. This sharing method is called share-by-copy (A copy of the library created in every module). There is a smarter way to share artifacts and that is through share-by-reference. In other words, place your library in a common place and every module would only contain a reference to it. How do you do this, let's see that now.
How to create a Shared Library:
1. Create your library in the usual way; Click on File-->New-->Library and give your library a name.
2. Once the library is created, click on "Dependencies" inside the library.
And under "Sharing Across Runtime Environments", select "Global". ("Module" is selected by default)
Done!That's all that needs to be done. Now, the library can be added as a dependency in any module you want.
To export this library to deploy on the server, click on File-->Export-->Business Integration-->"Integration modules and libraries", select the "Files for server deployment" radio button and select the library that you want to deploy as a shared library. This will create a .JAR file in the specified location.
We'll have a look in detail on how to deploy the .JAR file of the Shared library on the server in my next post.