11 Replies Latest reply on Apr 27, 2012 10:41 AM by foutjo

    Help Understanding AS-7 Classloading

    foutjo

      I have read the doc on AS7 classloading and I am still a bit confused on how to setup an external jar file to use with AS-7.

      I am hoping that someone can shed some light:)

       

      In my example I am trying to get XStream to work with my SLSB (Stateless Session Bean) running on AS-7.

       

      The SLSB has calls to the XStream api that require the xstream.jar file.

       

      My question is how do I setup JBoss- AS-7 to find the xstrean.jar file?

       

      In my simple example I have a java client call the SLSB.

      The SLSB has calls to the Xstream API.

       

      I have done a couple of things but I still must be missing something.

       

      I keep getting the following error:

       

                Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/XStreamException

       

       

      In the modules/ folder I added the following:

       

         com\thoughtworks\xstream\main

       

      Copied the xstream.jar file to the \main folder.

       

      Created the module.xml file:

       

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

        <module xmlns="urn:jboss:module:1.1" name="com.thoughtworks.xstream">

        <resources>

          <resource-root path="xstream-1.4.1.jar"/>

        </resources>

      </module>

       

      Here is where I get confused. 

       

      Should something go into the standalone.xml file?

      Do I need a domain.xml file?  I yes then where does it go?

      Do I need a jboss-deployment-structure.xml file?

       

      *One note is that this is not a web application.  It is a stand alone java client calling a SLSB.

       

      Any help is greatly appreciated. 

       

      Thanks.

        • 1. Re: Help Understanding AS-7 Classloading
          beve

          Hi,

          Do I need a jboss-deployment-structure.xml file?

          You need to specify that your EJB depends on the 'com.thoughtworks.xstream'  module that you have created. This can be done either by packaging a jboss-deployment-structure.xml in the META-INF directory of your EJB, or you can specify a manifest header as described here:

          https://docs.jboss.org/author/display/MODULES/Manifest+module+information

           

          Regards,

           

          /Daniel

          • 2. Re: Help Understanding AS-7 Classloading
            sfcoy

            Any particular reason you're not packaging it in your EAR file?

            • 3. Re: Help Understanding AS-7 Classloading
              foutjo

              Thanks Daniel. 

               

              I used the jboss-deployment-structure.xml approach and it worked like a charm.

              • 4. Re: Help Understanding AS-7 Classloading
                foutjo

                Stephen not being an expert my understanding of an .ear file was the following:

                It contains both the .war (Web Archive) file containing the web component of the application as well as the .jar file.

                 

                Since my application contained no web archive I left the application be just the .jar file.

                 

                Not sure how that would have helped me with my problem.

                Does the .ear file create the jboss-deployment-structure.xml for you?

                • 5. Re: Help Understanding AS-7 Classloading
                  beve

                  Not sure how that would have helped me with my problem.

                  You can package your application into an ear even if it does not contain a web app. With an EAR you can specify a deployment descriptor element in META-INF/application.xml, named 'library-directory'. This specifies the directory where your xstream.jar file can be placed. The default location is 'lib' so if you are happy with that location then just put the xstream.jar into the lib directory of your ear. This will give you a portable solution.

                   

                  Regards,

                   

                  /Daniel

                  • 6. Re: Help Understanding AS-7 Classloading
                    foutjo

                    Thanks for the EAR explanation Daniel.

                     

                    I am having one more problem with dependencies that I have to resolve.

                     

                    I am not getting the following class not found error:

                     

                    java.lang.NoClassDefFoundError: org/xml/sax/SAXException

                     

                    XStream uses sax so I'm not sure how I go about defining the depenency of Xstream for org/xml/sax.

                     

                    I thought sax was part of Java.

                     

                    Any idea on how I would support sax from within xstream?

                     

                    Thanks.

                    • 7. Re: Help Understanding AS-7 Classloading
                      beve

                      I think you'll need to add a dependency from the module.xml that you created:

                       

                      <module>
                         ...
                         <dependencies>
                              <module name="javax.api"/>       
                          </dependencies>
                      </module>
                      

                       

                      Regards,

                       

                      /Daniel

                      • 8. Re: Help Understanding AS-7 Classloading
                        sfcoy

                        If you put your jar in the EAR/lib directory then your EJB's will be able to see it and you will not need to use a module or jboss-deployment-structure.xml.

                         

                        This is standard JEE behaviour, and it has way less moving parts. Only make it as complicated as it needs to be.

                        • 9. Re: Help Understanding AS-7 Classloading
                          foutjo

                          Thanks Stephen.

                          Obviously I want to make this as less complicated as I can.

                           

                          Is there some documentation that you would recommend on how to create a correctly formatted ear file?

                          I have never created one before.

                           

                          Thanks.

                          • 10. Re: Help Understanding AS-7 Classloading
                            sfcoy

                            You can find a list of all of the Jave EE 6 specifications at Java EE 6 Technologies

                             

                            Download the one at the top (JSR-316) and have a look at Chapter EE.8.

                            • 11. Re: Help Understanding AS-7 Classloading
                              foutjo

                              Thanks.