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:
 weblogic-application.xml
<library-ref>
<library-name>my.shared.lib</library-name>
<specification-version>1.0</specification-version>
</library-ref>




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):
 weblogic-application.xml
<library-ref>
<library-name>my.shared.lib</library-name>
<specification-version>1.0</specification-version>
<context-root>MyFirstWebService-my-shared-lib</context-root>
</library-ref>


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.

-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...