Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've experienced a strange error coming out of the Weblogic wldeploy tool recently. It was reporting that a context path used by my shared library is already in use when I was trying to deploy a new web service. This seemed confusing to me - I had two web services that were both referencing the same shared library, the first service would deploy without any issues while the second would fail deployment with the context root error. Shared libraries by their nature are meant to be shared so what was the issue?

This was the kind of error I was seeing...
 Deployment Error
[wldeploy] Target state: deploy failed on Server my_server
[wldeploy] weblogic.application.ModuleException: Context path '/my_shared_lib' is already in use by the module: my_shared_lib application: MyFirstWebService

After a fair amount of research I stumbled upon this article: Configuring context root for web application libraries. This got me thinking.

My environment had my shared library deployed already, as a war file, following a process similar to this article. Lets assume the shared library name was my.shared.lib, both the implementation and specification versions were 1.0, and most importantly the war file name was my_shared_lib.war.

Now the first web service that was deployed was referencing this shared library from its weblogic-application.xml file like this:

Since the library reference is at the application level, the shared library is treated as a module of the application and hence requires its own context root. WebLogic takes the name of the war file sans the .war extension as the default value for the context root. In this case, it was my_shared_lib.

The second web service had the same identical weblogic-application.xml file so WebLogic tried to create the same context path for the shared library imported by that service, causing a name collision.

There are a number of solutions to this:
  • Move the library-ref to weblogic.xml file instead.
  • Adjust the context root of the imported library.

The first option is fairly simple, just cut and paste between two files.

The second option is achieved by adding a context-root element into library-ref that has a unique value for the context root based on the web service name so that the reference looks something like this (or really just any unique value):

The second web service would then have a different value for the context-root element. Redeploying both services solves the issue.

Both approaches are valid but my preferred one is to reference the library at the module level i.e. in the weblogic.xml file so that the library never gets its own module created inside the application in the first place.


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.