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

There is official documentation that outlines how Coherence applications can be deployed in WebLogic. This sways towards creating GAR archives, but what if you simply wanted to use Coherence in your existing JAX-WS or JAX-RS service? Well it isn't too much different, in fact the sample JSP app does something similar. In this post I'll outline two approaches to ensuring Coherence is configured as per your application's deployment descriptors every time.

I'm going to assume a standard Maven layout for your web app, with the src/main directory that contains java, resources and webapp directories within it. There are a number of deployment descriptor and configuration files in there too as shown below.
webapp.png


To configure Coherence for your web application, the tangosol-coherence-override.xml file must be in its classpath. That means it should be present in the WEB-INF/classes directory in your WAR file. Having it in that directory is not enough however, the weblogic.xml file also needs to have the following entry in it...
 weblogic.xml
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>


The above tells WebLogic to load files/classes found inside the WAR file in preference to those found elsewhere. Since a web application's classpath can include multiple locations across the WebLogic server's file system, it is a good idea to make sure that your web app loads your version of tangosol-coherence-override.xml and not some other one found elsewhere on the classpath.

The above approach works well for JAX-WS services since no additional library overrides are typically required. However if you want to use Jersey with WLS 12.1.2 or anything that forces your weblogic.xml to have the prefer-application-packages element defined the above approach doesn't work.

As per Oracle's documentation -
Note that in order to use prefer-application-packages or prefer-application-resources, prefer-web-inf-classes must be set to false.




So if you set prefer-application-packages in your weblogic.xml you must do the following to get your tangosol-coherence-override.xml file to be read from your WAR package...
 weblogic.xml
<prefer-application-resources>
<resource-name>coherence-*.xml</resource-name>
<resource-name>tangosol-*.xml</resource-name>
</prefer-application-resources>


That's it!

So there you go, two approaches for two different deployment types. The end result is your Coherence settings will be read from the WAR file instead of being picked up from another location on the classpath.

-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...