6 Replies Latest reply: Jun 10, 2013 10:43 AM by Julien Kronegg RSS

jboss 5.1.0.GA class loading, parent last

Charlie Yang Novice

Hi, I worked with a legacy app(WAR) these days. It works fine on Tomcat and Websphere(with parent last class loading). But when I deploy it on JBoss 5.1.0.GA, trouble comes.

My WAR contains some JARs which also shipped with JBoss, such as persistence api, hibernate*, jsf*...

I know it's class loading issue, I want my WAR use JARs under its own WEB-INF/lib. I searched on the internet for a solution, but I didn't work it out.

 

I read this article (ClassLoadingConfiguration) and tried, but not work.

 

According to the article, I add the class loading config in the jboss-web.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"
        "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>
    <!--<class-loading java2ClassLoadingCompliance="true"/>-->
 
    <class-loading java2ClassLoadingCompliance="false">
        <loader-repository>
            com.example:loader=3plweb.war
            <loader-repository-config>
                java2ParentDelegation=false
            </loader-repository-config>
        </loader-repository>
    </class-loading>
    <context-root>3plweb</context-root>
</jboss-web>

 

this should use the parent last policy to load classes. But the conflict remains, ClassCastException was thrown(and some other exceptions that also caused by conflict).

 

java.lang.ClassCastException: 
org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider

ejb3-persistence-api.jar in my WAR conflicts with that in JBoss's common/lib

 

and I tried

 

<class-loading java2ClassLoadingCompliance="true"/>

It works, but it use parent first policy, and hibernate*.jar/jsf*.jar/... in my WAR are not load. That's not what I want.

 

Any ideas?

 

Attached is error log for your reference.

Thanks in advance.

  • 1. Re: jboss 5.1.0.GA class loading, parent last
    jaikiran pai Master

    Charlie Yang wrote:

     


     

    I read this article (ClassLoadingConfiguration) and tried, but not work.

     

    Charlie, that article has an important note for JBoss AS 4.2.x (and later versions):

     

     

    Note for AS 4.2.x and later versions: As of at least  JBoss 4.2.1, the <class-loading> tag in jboss-web.xml appears to  no longer be supported as isolation is ignored. Instead, the following  configuration appears to accomplish the same goal:

     
    <jboss-web>
       <loader-repository> 
          com.example:archive=unique-archive-name 
       </loader-repository> 
    </jboss-web> 
    

    See if changing the jboss-web.xml to something like the above works.

     

    P.S: From what I see in the forum threads, overriding the JSF version might not be possible. But give it a try let's see.

  • 2. Re: jboss 5.1.0.GA class loading, parent last
    Charlie Yang Novice

    hi jaikiran, thanks for your reply.

     

    I noticed the "Note for AS 4.2.x and later versions" when I read the article.

    But what confuses me is that loader-repository is a child element of class-loading according to the dtd, and it is not allowed as a direct child under jboss-web.

    Anyway, let's have a try, maybe something magical will happen.

    But unfortunately, no magic, see exception below

    Caused by: org.jboss.xb.binding.JBossXBRuntimeException: 
    loader-repository not found as a child of jboss-web in unordered_sequence: 
    security-role* max-active-sessions? webservice-description* class-loading? 
    jacc-star-role-allow? message-destination* servlet* replication-config? 
    passivation-config? context-root? security-domain? virtual-host* 
    use-session-cookies? depends* {unordered_sequence jndiEnvironmentRefsGroup}?
    ...
    
    

     

    I also tried the different versions of dtd and even removed the dtd header, but nothing changed:<

     

    Did any one encounter the same problem as me? How did you fix this?

  • 4. Re: jboss 5.1.0.GA class loading, parent last
    Andres Ederra Newbie

    Hi Charlie,

    Same problem here, but fortunately I've found a solution for 5.1.0.GA (and 5.0.0 EAP too...)

    It seems that defining the classloading strategy using jboss-web.xml descriptor is not working anymore for wars, at least in 5.1.0.GA

    But this version includes another way for defining custom classpaths, using the jboss-classloader.xml descriptor.

    In short, you have to define the following xml as jboss-classloader.xml file in your WEB-INF:

     

     

    <classloading xmlns="urn:jboss:classloading:1.0"
                  domain="YourAppNameDomain"
                  export-all="NON_EMPTY"
                  import-all="true">
    </classloading>

     

     

    That tells JBoss classloader to behave as a classic webapp classloader: your WEB-INF goes first, and later the system classloader.


    Now... the syntax for this jboss-classloader.xml can be considered as magic, as there is not yet any clear documentation of its syntax (please, someone who knows this stuff, consider documenting it, in the microcontainer docs i guess because todays docs for it are empty!!! see: http://docs.jboss.org/jbossmc/docs/2.0.x/userGuide/pt06.html)


    For further investigations here there are some pointers:


    http://community.jboss.org/wiki/JBoss5custommetadatafiles
    http://community.jboss.org/thread/96677?tstart=0


    http://www.mastertheboss.com/en/jboss-server/223-solving-jboss-5-classloading-issues.html
    http://java.dzone.com/articles/jboss-microcontainer-classloading


    Hope this helps...

  • 5. Re: jboss 5.1.0.GA class loading, parent last
    jaikiran pai Master

    Andres Ederra wrote:

     

    Hi Charlie,

    Same problem here, but fortunately I've found a solution for 5.1.0.GA (and 5.0.0 EAP too...)

    It seems that defining the classloading strategy using jboss-web.xml descriptor is not working anymore for wars, at least in 5.1.0.GA


    If that's the case, then it's a bug. If you have a simple application which reproduces this, then please create a JIRA and attach the application there.

  • 6. Re: jboss 5.1.0.GA class loading, parent last
    Julien Kronegg Novice

    Note that the file is name jboss-classloading.xml, not jboss-classloader.xml.