12 Replies Latest reply on Apr 16, 2013 2:54 AM by chandrasachin16

    Some issues while migrating application from Jboss 5 to 7

    chandrasachin16 Newbie

      Hi All,

       

      We are in the process of migrating our Application from Jboss 5 to Jboss as 7. We are using Jboss AS 7.1.0. and JDK 1.7.  We have studied that jboss AS 7 is modular and uses module based loading.Basically we are facing issues with JAXB. We are able to resolve couple of issues but we are stuck up while creating jaxb instance. Our code is as below:

       

      JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core"); //$NON-NLS-1$

       

      This is actually happening during the deployment of our ear file which internally uses  a jar file having a class (MesEnvironment) which has  the above code.The error we are getting is

       

      18:19:59,373 ERROR [stderr] (MSC service thread 1-2) javax.xml.bind.JAXBException: "com.package.schemas.core" doesnt contain ObjectFactory.class or jaxb.index

       

      18:19:59,374 ERROR [stderr] (MSC service thread 1-2)     at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:231)

       

      18:19:59,376 ERROR [stderr] (MSC service thread 1-2)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       

      18:19:59,377 ERROR [stderr] (MSC service thread 1-2)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

       

      18:19:59,378 ERROR [stderr] (MSC service thread 1-2)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

       

      18:19:59,379 ERROR [stderr] (MSC service thread 1-2)     at java.lang.reflect.Method.invoke(Unknown Source)

       

      18:19:59,380 ERROR [stderr] (MSC service thread 1-2)     at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:137)

       

      18:19:59,381 ERROR [stderr] (MSC service thread 1-2)     at javax.xml.bind.ContextFinder.find(ContextFinder.java:294)

       

      18:19:59,382 ERROR [stderr] (MSC service thread 1-2)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)

       

      18:19:59,383 ERROR [stderr] (MSC service thread 1-2)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375)

       

      18:19:59,384 ERROR [stderr] (MSC service thread 1-2)     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279)

       

       

      We tried to search this in forums and came across my solutions but nothing is worknig out. We used all types of possibilites but didn't had any luck. We also debugged inside the libraray by downloading the source code which gives error in the ContextFactory class at this line :---------------------   o = classLoader.loadClass(pkg+".ObjectFactory");  even though the ObjectFactory Class is in the package.

       

      Also tried with  JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core",com.package.schemas.core.ObjectFactory.class.getClassLoader());     and

      JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core",com.package.schemas.core.MesEnvironment.class.getClassLoader());  // but couldn't solve

       

       

      So we decided to put this here if somebody can throw some light on it . Is it something which we can resolve or is it that cannot be resolved in current jboss release.

       

       

      Regards

      Sachin

        • 1. Re: Some issues while migrating application from Jboss 5 to 7
          Frank Langelage Master

          Tell us more about your packaging.

          As far I understood you have an ear as the deployment unit.

          ear contains a jar "internally". Where is this located? Mentioned in META-INF/application.xml as module or in ear's lib folder?

          Within this jar there is a class doing

          JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core"); //$NON-NLS-1$

          Where is com.package.schemas.core.ObjectFactory.class located? In the same jar as the class mentioned above or in another jar file within the same ear?

          • 2. Re: Some issues while migrating application from Jboss 5 to 7
            chandrasachin16 Newbie

            Hi Frank,

                    First of all thanks for replying me. The packaging structure of our ear(xmes.ear) is as given below

                    xmes.ear ( which contains the following)

                            --- servicelayer.jar

                            --- OperatorUI_Services.war

                            --- OperatorUI_EJB.jar

                            --- adminui.war

                            --- META-INF ( application.xml, MANIFEST.MF, jboss-deployment-structure.xml)

                            --- mes-engine.jar

                            --- lib( containing necessary jars)

                           

                            MANIFEST.MF has been set to the following -

                            Dependencies: org.jboss.ws.cxf.jbossws-cxf-client services export,com.sun.xml.bind services export,org.apache.cxf services

                           

                            jboss-deployment-structure.xml has also been used to set some dependencies( eg. jsf)

                            Our application.xml defines the list of jar and war packaged in the ear

               

               

               

               

            Packaging Structure of mes-engine.jar is as given below:

                           mes-engine.jar ( containing the following)

                                       ---- META-INF

                                       ---- jaxb.properties

                                       ---- hibernatexBatch.properties

                                       ---- config(folder)

                                                  ---mes (folder)

                                                      ---- mes.xml( file to be unmarshalled by using JaxB during deployment)       //   config/mes/mes.xml

                                       ---- com.package.module.configuration (name of package inside mes-engine.jar) has  MesEnvironment.class which creates JAXB instance

                                      

                                       ---- com.package.schemas.core ( another package inside the mes-engine.jar having the ObjectFactory.class which initializes list of objects).

                                      

                                     

            The MesEnvironment.class has the following code -

            JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core"); ( was working in Jboss  5)  but with Jboss 7 it's not working at all.

             

            Also the application.xml is something like this

            <application>

            <module>

                <web>

                  <web-uri>OperatorUI_Services.war</web-uri>

                  <context-root>MESServices</context-root>

                </web>

              </module>

               <module>

                <web>

                  <web-uri>adminui.war</web-uri>

                  <context-root>adminui</context-root>

                </web>

              </module>

              <module>

                <ejb>OperatorUI_EJB.jar</ejb>

              </module>

               <module>

                <ejb>servicelayer.jar</ejb>

              </module>

              <module>

                <ejb>mes-engine.jar</ejb>

              </module>

              <library-directory>lib</library-directory>

            </application>

             

             

            Regards

            Sachin

            • 3. Re: Some issues while migrating application from Jboss 5 to 7
              Frank Langelage Master

              If I understood everything right,in your case the MesEnvironment.class containing the call of

              JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core");

              and the ObjectFactory.class

              are in the same jat within the ear.

              Right?

              Then finding the class should not be a problem at all.

               

              I had a look at my packaging:

              I have an ejb module conatining a class calling e.g.

              JAXBContext jaxbc = JAXBContext.newInstance( "net.twt.insight.v7.Organizations", this.getClass().getClassLoader() );

              Package net.twt.insight.v7.Organizations is in this case located in a separate jar file within the the lib folder of the ear.

               

              Perhaps specifing the classloader the way I do helps you.

              • 4. Re: Some issues while migrating application from Jboss 5 to 7
                chandrasachin16 Newbie

                Hi,

                 

                Tried with the same solution

                 

                JAXBContext jaxbContext = JAXBContext.newInstance("com.package.schemas.core",MesEnvironment.class.getClassLoader());     // since my method is static so used  MesEnvironment.class.getClassLoader()

                 

                but not working. It's really surprising that, even though  I am not using TCCL and using  the current class loader but still the result is same.

                 

                Don't know what I am missing ?

                 

                Just to make sure if the dependencies are ok or not. Am I using the right dependencies ?

                Dependencies: org.jboss.ws.cxf.jbossws-cxf-client services export,com.sun.xml.bind services export,org.apache.cxf services  

                 

                Is there any other dependencies to be set ?

                Do I need to use Jboss as 7.1.1 ?

                 

                Regards

                Sachin

                • 5. Re: Some issues while migrating application from Jboss 5 to 7
                  Frank Langelage Master

                  Okay, another idea.

                  For what you need those Dependencies you declared?

                  You're using classes out of org.jboss.ws.cxf.jbossws-cxf-client and org.apache.cxf services in your code directly in your code or can you get rid of them?

                   

                  I read that failure messages like your's usually have to do with version conflicts.

                   

                  I do not have declared those dependencies and can succesfully use JAXBContext.

                  In this case I think the JAXB coming with the Java runtime is used instead of the JBoss AS7 version.

                  In my case Java 6 and Java 7 runtime both work.

                  • 6. Re: Some issues while migrating application from Jboss 5 to 7
                    Stephen Coy Master

                    If com.package.schemas.core.ObjectFactory contains references to classes that are in the EAR's WAR files then JAXB will be unable to load it.

                     

                    Earlier JBoss versions were a lot more liberal in this regard.

                     

                    Additionally, the Servlet, JSP, JSF, EL, JSTL and JAX-RS APIs are not automatically available to classes in EJB modules. See table EE6.1 in the JEE6 spec.

                     

                    You can configure your way out of this using a jboss-deployment-structure.xml file as described in Class Loading in AS7.

                    • 7. Re: Some issues while migrating application from Jboss 5 to 7
                      chandrasachin16 Newbie

                      Ok I think this could be the problem which you are trying to highlight . My xmes.ear has lib folder as I had mentioned above (runtime jars)

                      In the lib folder I have the following jars:-

                       

                      jaxb-api-1.0.jar, jaxb-impl-1.0.6.jar , jaxb-xjc-1.0.6.jar

                       

                      The Jboss also has the jars which are in the module folder as follows:

                       

                      Module(com\sun\xml\bind)

                      jaxb-xjc-2.2.4.jar , jaxb-impl-2.2.4.jar

                       

                      Another one in module (javax\xml\bind\api)

                      jboss-jaxb-api_2.2_spec-1.0.3.Final.jar

                       

                      Just correct me if I am wrong, is it that I need to suppress the module like this

                      <exclusions>

                              <module name="com.sun.xml.bind" slot="main" />

                              <module name="javax.xml.bind.api" slot="main" />

                      </exclusions>-->

                       

                      and add a dependency something like :---

                       

                      <module name="deployment.xmes.ear.jaxb-api-1.0.jar" />

                      <module name="deployment.xmes.ear.jaxb-impl-1.0.6.jar" />

                      <module name="deployment.xmes.ear.jaxb-xjc-1.0.6.jar" />

                       

                      Regards

                      Sachin

                      • 8. Re: Some issues while migrating application from Jboss 5 to 7
                        Stephen Coy Master

                        Unfortunately exclusions are not supported in JBoss AS 7.1.0 or 7.1.1. This facility was added for 7.1.2 or 7.1.3, I can't recall which.

                         

                        You should really update your code to use the newer JAXB APIs.

                         

                        I'm slightly surprised that you did not have problems in JBoss 5.

                         

                        Replacing any javax.* classes with different versions in your application is never a good idea as a general rule, as it can lead to all sorts of problems such as ClassNotFoundExceptions and the like.

                        • 9. Re: Some issues while migrating application from Jboss 5 to 7
                          Frank Langelage Master

                          You really need those old jar's in your lib folder? I'd recommend you to get rid of them.

                           

                          So you won't need exclusions and any additional dependencies.

                          The dependencies anyway are not needed, because anything in your ear/lib folder is available to classpath.

                           

                          According to https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments

                          javax.xml.bind.api is added automatically if JAX-RS (Resteasy) subsystem is available in your config.

                           

                          As said before I do not have dependencies or exclusions defined nor such libs in ear/lib folder and do not have problems to use JAXB.

                          • 10. Re: Some issues while migrating application from Jboss 5 to 7
                            chandrasachin16 Newbie

                            Hi ,

                             

                                       I got your point Frank . Yes now I need to get rid of my old jars and also as suggested by Stephen. This was occuring because in our product build script we have two folders buildtime jars and runtime jars. The runtime jars get copied to the lib folder of the ear file. I need to modify the ant build script of our product . It's a complex framework and need to modify lot many things . I will keep you posted.

                             

                             

                            Thanks a lot to both of you for your valuable suggestions.

                             

                            Regards

                            Sachin

                            • 11. Re: Some issues while migrating application from Jboss 5 to 7
                              chandrasachin16 Newbie

                              Hi ,

                               

                              Sorry I couldn't update you on the this topic. I had to deliver another billable assignment. As per the last discussion I did modifications as follows.

                               

                              1. Downloaded the Jaxb2 jars and correspondingly hyperjaxb3 jars  along with the dependent jars. My existing build script uses Jaxb1 and hyperjaxb2 jars at build time.

                              2. So now I removed the old jars with hyperjaxb3 and jaxb2 jars. As far as I understood  when the product was designed, we had used hyperjaxb2 with jaxb1 to generate the hibernate mapping files and java classes as per the     schema(.xsd files) .

                              3. Modified my ant build script and also all the schema file(.xsd) which are quite big in number, after reading the tutorials.

                               

                              The interesting thing I found here was that-

                               

                              1. The earlier build script had arguments in xjc task something like this -

                               

                              <xjc1 package="com.package.schemas.core" target= "${generateJaxbSourceHere}" extension="true">

                                          <arg line="

                                              -Xequals

                                              -XhashCode

                                              -Xhyperjaxb2

                                              -Xhyperjaxb2-config=${basedir}/config/mes/hyperjaxb2.config.xml"/>

                               

                              where -Xhyperjaxb2-config was used to pass a bean configuration file (hyperjaxb2.config.xml)  and where we were overriding the "typeStrategy" like this

                               

                              <bean name="typeStrategy"

                                      class="com.package.mesutil.hyperjaxb2.XMESDefaultTypeStrategy"/>    (XMESDefaultTypeStrategy extends org.jvnet.hyperjaxb2.hibernate.mapping.strategy.type.DefaultTypeStrategy)

                               

                               

                               

                              I had gone through the hyperjaxb3 tutorial where it tells we need to do something like this -

                               

                              <arg line="

                                  -Xequals

                                  -XhashCode

                                  -Xhyperjaxb3-ejb

                               

                              This thing works and I am able to generate the annotated java classes as per the schema defined, but my second build script fails because it actually compiles approximately 100 utility classes which references the implementation classes of those interfaces which were generated during compiliation of .xsd files. Now again a new thing. The Jaxb2 does not generate the implementaion classes for interfaces anymore as per the tutorial which makes it lightweight. I have started changing the references of implementation classes to the newely generated classes(annotated). Does this mean that there is no other option left, but to change the references in these 100 utility classes or is there a workaround for this ?

                               

                              Another thing to add is now -Xhyperjaxb2-config it is no more supported in hyperjaxb3 as an argument . How do I pass such configuration ? It's basically a customization which we were doing.

                               

                              Regards

                              Sachin

                              • 12. Re: Some issues while migrating application from Jboss 5 to 7
                                chandrasachin16 Newbie

                                Hi ,

                                 

                                Sorry I couldn't update you on the this topic. I had to deliver another billable assignment. As per the last discussion I did modifications as follows.

                                 

                                1. Downloaded the Jaxb2 jars and correspondingly hyperjaxb3 jars  along with the dependent jars. My existing build script uses Jaxb1 and hyperjaxb2 jars at build time.

                                2. So now I removed the old jars with hyperjaxb3 and jaxb2 jars. As far as I understood  when the product was designed, we had used hyperjaxb2 with jaxb1 to generate the hibernate mapping files and java classes as per the     schema(.xsd files) .

                                3. Modified my ant build script and also all the schema file(.xsd) which are quite big in number, after reading the tutorials.

                                 

                                The interesting thing I found here was that-

                                 

                                1. The earlier build script had arguments in xjc task something like this -

                                 

                                <xjc1 package="com.package.schemas.core" target= "${generateJaxbSourceHere}" extension="true">

                                            <arg line="

                                                -Xequals

                                                -XhashCode

                                                -Xhyperjaxb2

                                                -Xhyperjaxb2-config=${basedir}/config/mes/hyperjaxb2.config.xml"/>

                                 

                                where -Xhyperjaxb2-config was used to pass a bean configuration file (hyperjaxb2.config.xml)  and where we were overriding the "typeStrategy" like this

                                 

                                <bean name="typeStrategy"

                                        class="com.package.mesutil.hyperjaxb2.XMESDefaultTypeStrategy"/>    (XMESDefaultTypeStrategy extends org.jvnet.hyperjaxb2.hibernate.mapping.strategy.type.DefaultTypeStrategy)

                                 

                                 

                                 

                                I had gone through the hyperjaxb3 tutorial where it tells we need to do something like this -

                                 

                                <arg line="

                                    -Xequals

                                    -XhashCode

                                    -Xhyperjaxb3-ejb

                                 

                                This thing works and I am able to generate the annotated java classes as per the schema defined, but my second build script fails because it actually compiles approximately 100 utility classes which references the implementation classes of those interfaces which were generated during compiliation of .xsd files. Now again a new thing. The Jaxb2 does not generate the implementaion classes for interfaces anymore as per the tutorial which makes it lightweight. I have started changing the references of implementation classes to the newely generated classes(annotated). Does this mean that there is no other option left, but to change the references in these 100 utility classes or is there a workaround for this ?

                                 

                                Another thing to add is now -Xhyperjaxb2-config it is no more supported in hyperjaxb3 as an argument . How do I pass such configuration ? It's basically a customization which we were doing.

                                 

                                Regards

                                Sachin