Weblogic Guava issue when deploying application

懵懂的女人 提交于 2019-11-29 12:10:55

It looks like you're running against a different version of Guava than you compiled against. Possibly you are running against multiple versions of Guava, and you are randomly getting the wrong one. This may be happening if one of your other dependencies has wrongly bundled Guava.

To figure out where this copy of MoreExecutors is coming from, I've heard that you can find it reflectively by using this snippet in UserServer:

MoreExecutors.class.getProtectionDomain().getCodeSource().getLocation()
Ric

It seems this a recurring question ([1], [2], [3]). I, myself, have stumbled upon this same problem. Weblogic is loading first it's own version of the (outdated) guava lib confliting with your applcation's version.

The solution is to add the prefer-application-packages to your weblogic.xml or weblogic-application.xml:

<wls:container-descriptor>
    <wls:prefer-application-packages>
            <wls:package-name>com.google.common.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:container-descriptor>

Is it a WAR project? Or is it just a EJB jar?

If the latest one, you've got a few options:

  • wrap your jar file into a EAR and deliver Guava's jar in it
  • add Guava's jar to the library folder of your AS
  • merge your jar file with Guava's one. For example, you can use Maven Shade Plugin if you're a Maven guy

I faced the similar issue. I could resolve this problem by adding a weblogic-application.xml with prefer-application-packages to my EAR.

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                            xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.0/weblogic-application.xsd">
    <prefer-application-packages>
        <package-name>com.google.common.*</package-name>
    </prefer-application-packages>
</weblogic-application>
Jeff Sneden

I ran across this issue as well, unfortunately altering the weblogic.xml didn't work for me. What did work, was dropping the guava-14.0.1.jar into $JAVA_HOME/jre/lib/endorsed (create this directory if it doesn't exist.)

One other word of caution: at first I tried using the more recent guava-18 - this caused a compatibility issue the other way (IllegalAccessError on MapMaker.makeComputingMap - more details here). Guava 14.0.1 seems to hit the sweet spot for me - the MapMaker class is old enough to satisfy WebLogic while the MoreExecutors class is new enough to make the Cassandra Java driver work (which is how I stumbled upon this issue.)

I managed to solve this problem using both files: weblogic-application.xml in ear and weblogic.xml in war

This is weblogic-application.xml in ear -> src/main/application/META-INF/

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
    <wls:prefer-application-packages>
        <wls:package-name>com.google.common.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:weblogic-application>

This is weblogic.xml in war -> src/main/webapp/WEB-INF/

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
    <wls:prefer-application-packages>
        <wls:package-name>com.google.common.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:weblogic-application>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!