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

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.