Guava/Logback and Weblogic12c

Using Google’s Guava libraries with Oracle’s Weblogic 12c is not a no-brainer. This is the result of Weblogic using a very old version of the Google Collections library, which is the predecessor of Guava, provides the same classes and more, but also uses the same package name – “…/weblogic12/modules/com.google.common_1.0.0.0_0-6.jar”.

Of course there is a very simple “solution” that you can find on many places on the web (e.g. here and here): replace the Weblogic file with a renamed updated version of the library.

This solution is obviously suicide for any stable production environment, despite of the fact that this seem to work at first sight. It’s like installing a Nitro injection in your car with the risk that the motor explodes one moment or another.

However, there is a clean solution to the problem. In the “weblogic.xml” file, you can tell Weblogic to prefer the libraries provided in your classpath to the ones provided in  Weblogic’s classpath. This applies to your application only. The same works well, by the way, if you want to use SLF4J and Logback instead of Weblogic’s Log4J.

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns .../.. .web-app/1.3/weblogic-web-app.xsd">
      :
      <container-descriptor>
          :
          :
          <prefer-application-packages</a>>
               <!-- Priority is given to SLF4J / Logback JARs embedded with the WAR instead of Weblogic's log4j -->
               <package-name>org.slf4j</package-name>
               <package-name>com.google.collections</package-name>
          </prefer-application-packages>
          :
          <prefer-application-resources>
              <resource-name>
                   org/slf4j/impl/StaticLoggerBinder.class
              </resource-name>
          </prefer-application-resources>
          :
      </container-descriptor>
      :
   </weblogic-web-app>

The same should be possible using the <prefer-web-inf-classes> tag instead, but I never tried this possibility.

One thought on “Guava/Logback and Weblogic12c”

  1. If I’m specifying com.google.common
    I get another error when I try to start the app in weblogic:

    java.lang.NoSuchMethodException: com.google.common.base.internal.Finalizer.startFinalizer(java.lang.Class, java.lang.ref.ReferenceQueue, java.lang.ref.PhantomReference)

Leave a Reply

Your email address will not be published. Required fields are marked *