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_18.104.22.168_0-6.jar”.
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.