Weblogic 10.3.1.0 is using com.bea.core.apache.commons.net_1.0.0.0_1-4-1.jar... I want to use commons-net-2.0.jar from my code

17,638

Solution 1

I want to use commons-net-2.0.jar from my code.

WebLogic uses a parent class loader first strategy and you basically have two options to tweak this behavior:

  • Use the prefer-web-inf-classes element in a weblogic.xml Web application deployment descriptor (that goes in WEB-INF next to the web.xml) ~or~
  • Package your war insider an EAR and use WebLogic Filtering classloader that you configure in a weblogic-application.xml descriptor (that goes in META-INF next to the application.xml)

Here is an example weblogic.xml:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
 xmlns="http://www.bea.com/ns/weblogic/90"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic- web-app.xsd">
    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
     </container-descriptor>
</weblogic-web-app>

Here is an example weblogic-application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
    <application-param>
        <param-name>webapp.encoding.default</param-name>
        <param-value>UTF-8</param-value>
    </application-param>
    <prefer-application-packages>
        <package-name>javax.jws.*</package-name>
    </prefer-application-packages>
</weblogic-application>

The former option is simpler but is global to the webapp. The later introduces more complexity if you're not currently using an EAR packaging but gives finer control.

See also

Solution 2

Have you tried putting the required JAR in \WEB-INF\lib of the WAR, \APP-INF\lib of the EAR or the \lib directory of the EAR file?

If your project is a standalone web project (with no EJBs), placing the JAR in WEB-INF\lib should be sufficient. For enterprise applications that possibly have EJB modules and Web modules bundled in a EAR file, APP-INF\lib should work, although I'm not so sure about WebLogic Server's support for the library directory (usually a \lib directory in the EAR file, but sometimes configurable via application.xml) concept brought out in Java EE 5.

EDIT: In the scenario where the application server's library is loaded ahead of the one present in the application, WebLogic Server's feature of filtered classloaders will aid in ensuring that the application always has the right classes loaded from its classpath, instead of the server's classpath.

Share:
17,638
Cal
Author by

Cal

Updated on June 25, 2022

Comments

  • Cal
    Cal almost 2 years

    Weblogic 10.3.1.0 is using com.bea.core.apache.commons.net_1.0.0.0_1-4-1.jar... I want to use commons-net-2.0.jar from my code.

    How can I force it to use the newer JAR in my code only?

  • Cal
    Cal almost 14 years
    Yes... I have commons-net-2.0.jar in the EAR file's lib folder and that works for other dependencies. But at runtime it is using the one from Weblogic... bea/modules/com.bea.core.apache.commons.net_1.0.0.0_1-4-1.ja‌​r
  • Vineet Reynolds
    Vineet Reynolds almost 14 years
    Oh ok, then it appears that the one from the server has already been loaded. I've updated my answer. Although the link is for WLS 10.3, it applies even for 10.3.1.