7 Replies Latest reply on Dec 14, 2011 11:40 AM by miragpl

    EAR deployment ClassNotFoundException when library exists

    Tom Fusillo Newbie

      Hi,

       

      I'm trying to deploy an ear on AS 6.0 Final.  When I deploy the ear I am receiving an ClassNotFoundException for org.springframework.context.ApplicationListener in the deployment of myapp.war,  although the library exists in the ear lib directory.  If I move the  necessary jars into the $JBOSS_HOME/common/lib directory, I no longer  receive this error.  I'm assuming that this is a classpath loading issue, but still can't figure out how to get it to work.  Any help with this will be greatly appreciated.

       

      The ear format is as follows:

       

      -packager.ear

           -lib

                -org.springframework.context-3.0.5.RELEASE.jar

                -other misc jar's

           -META-INF

                -jboss-app.xml

                -application.xml

           -myapp.war

                -WEB-INF

                     -web.xml

       

      Here is my jboss-app.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss-app PUBLIC
          "-//JBoss//DTD Java EE Application 5.0//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd">
      <jboss-app>
        <loader-repository>smartGridPackage:loader=packager.ear

           <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
        </loader-repository>
      </jboss-app>

        • 1. Re: EAR deployment ClassNotFoundException when library exists
          Radim Hanus Expert

          Hi Tom,

           

          recently I encounter the same problem and found solution in Ales Justin's article on dzone

          http://java.dzone.com/articles/jboss-microcontainer-classloading

           

          so try to add jboss-classloading.xml descriptor with following content into myapp.war/WEB-INF

          <?xml version="1.0" encoding="UTF-8"?>

          <classloading xmlns="urn:jboss:classloading:1.0"
                        domain="smartGridPackage:loader=packager.ear"
                        parent-domain="DefaultDomain"
                        j2seClassLoadingCompliance="true"
                        export-all="NON_EMPTY"
                        import-all="true">
          </classloading>

           

          hopefully it helps you and saves a day of research as I had to spend :-)

          Radim

          • 2. Re: EAR deployment ClassNotFoundException when library exists
            Tom Fusillo Newbie

            Thanks, Radim. I fixed my error. The problem was a little more in depth than I thought.

             

            The problem:

             

            I was trying to use the CXF libraries that JBoss 6 came packaged with. I was building my application with Maven and listed the dependencies as provided. When my application was deploying it was deploying the web services and then trying to reference my Spring libraries included in the ear. These Spring libraries were not visible to the CXF libraries.

             

            The solution:

             

            I removed the provided scope on the CXF dependencies to include them in my ear and I added the jboss-classloading.xml from above and added the line parent-first="false" so the file looks as such:

             

            <?xml version="1.0" encoding="UTF-8"?>
            
            <classloading xmlns="urn:jboss:classloading:1.0"
                          domain="smartGridPackage:loader=packager.ear"
                          parent-domain="DefaultDomain"
                          parent-first="false"
                          export-all="NON_EMPTY"
                          import-all="true">
            </classloading>
            

             

             

            I'm not sure why the CXF libraries were trying to reference the Spring libraries but my application is deploying properly now.

            • 3. Re: EAR deployment ClassNotFoundException when library exists
              Radim Hanus Expert

              ah sorry I copied it out of an experimental version

              j2seClassLoadingCompliance is not a valid attribute of classloading -> parent-first is the right one

              • 4. Re: EAR deployment ClassNotFoundException when library exists
                Kuntal Mondal Newbie

                Hi Tom,

                I have the exact similar application configuration and I followed your approach - I have few confusion. Can you please take a look into these?

                  1) I believe the CXF library set which are part of jboss/common/lib, should be there even if I put these as part of my EAR/lib - is this correct ?

                  2) Can you please let me know what are the CXF-libs you put from common/lib? I find there are 31 libs with file-name started with "cxf-xxx".

                      Do I need to copy any other CXF related library (from jboss/client) or other dependent libs?

                  3) Do I need to put any other deployment-descriptor file (like jboss-cxf.xml, etc) as part of my EAR deployment?

                 

                In my case I am invoking the webservice, rather than deploying the webservice. Thus if I put all CXF libs under my EAR/lib, my app comes up fine. But when I make the webservice call, it needs other depenedent library like (jaxb-api, stax-api,etc) - and all those libs are part of either jboss/common/lib or jboss/client - so I am again ended up with same classloader-violation issue for those lib.

                Because now my CXF libs are loaded by EAR-classloader but internally these look for other 3rd party libs which are loaded by Jboss BaseClassLoader.

                I am uncessful to find out the exact set of dependent libs I need to put as part of my EAR/lib beside the CXF libray set.

                 

                Is it possible to share your list of lib-names related to webservice deployment (as part of EAR and/or WAR)?

                 

                Thanks a lot for your help and tips.

                -

                • 5. Re: EAR deployment ClassNotFoundException when library exists
                  Tom Fusillo Newbie

                   

                    1) I believe the CXF library set which are part of jboss/common/lib, should be there even if I put these as part of my EAR/lib - is this correct ?

                       Yes, this is fine as long as you have jboss-classloading.xml in the EAR.

                   

                    2) Can you please let me know what are the CXF-libs you put from common/lib? I find there are 31 libs with file-name started with "cxf-xxx".

                        Do I need to copy any other CXF related library (from jboss/client) or other dependent libs?


                       Only pull in the CXF dependencies that you need to run your application.  You should not need any other libs.  In my case the only dependency I listed in Maven was cxf-rt-frontend-jaxrs and this pulled in the other required CXF libraries. 

                   

                    3) Do I need to put any other deployment-descriptor file (like jboss-cxf.xml, etc) as part of my EAR deployment?

                       I have a bean context that is a parameter for my web.xml in the WAR that I deploy. This may vary since you're invoking your web service instead of deploying it. 

                   

                  As for your problem loading the jaxb and stax apis. Make sure you have your jboss-app.xml configured properly in the META-INF of your EAR. I hope this helps.

                   

                  -Tom

                  • 6. EAR deployment ClassNotFoundException when library exists
                    Dipti Vaidya Newbie

                    Hi Tom,

                    I'm unable to deploy my ear which has the cxf libraries bundled in the app on Jboss AS 6. I made the jboss-classloading.xml as you suggested above, but still cant get it to work.

                    Can you please share your jboss-app.xml as well?

                    • 7. Re: EAR deployment ClassNotFoundException when library exists
                      miragpl Newbie

                      Hi all,

                       

                      I have similar problem. I use CXF together with spring in my web app project (i have only .war). First I wanted only to have  spring jars in my WEB-INF/lib and use cxf from jboss. But I got following error:

                       

                        Deployment "vfs:///D:/dev/java/tools/servers/jboss-6.1.0.Final/server/myapp/deploy/myapp.war" is in error due to the following reason(s): java.lang.ClassNotFoundException: org.springframework.context.ApplicationListener

                       

                      Then I read this discussion and I tried to put cxf and spring withing the WEB-INF/lib and  use jboss-classloading.xml. This time I got following example:

                       

                      Deployment "vfs:///D:/dev/java/tools/servers/jboss-6.1.0.Final/server/myapp/deploy/myapp.war" is in error due to the following reason(s): java.lang.IllegalStateException: Unresolved conflict on resource environment reference named: cxf

                       

                      The  jboss-classloading.xml I used below.

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <classloading xmlns="urn:jboss:classloading:1.0"

                                    domain="myapp.war"

                                    parent-domain="DefaultDomain"

                                    parent-first="false"

                                    export-all="NON_EMPTY"

                                    import-all="true">

                      </classloading>

                       

                       

                      When I put spring libraries into jboss/myapp/lib folder everything works. Unfortunatelly it's not the solution that I was looking for.

                      Could anyone provide any hint/solution?

                       

                       

                      Thanks in advance!