14 Replies Latest reply: Oct 3, 2012 3:22 PM by Blaise Doughan-Oracle RSS

    Bug: OEPE 12c JAXB

    dvohra21
      JAXB context does not get initialized in OEPE 12c.

      jaxb.properties is
      javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory


      JAXBContext jaxbContext = JAXBContext.newInstance("jaxb");

      generates error
      javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory could not be instantiated: javax.xml.bind.JAXBException
      - with linked exception:
      +[java.lang.NullPointerException]     +
      - with linked exception:
      +[javax.xml.bind.JAXBException+
      - with linked exception:
      +[java.lang.NullPointerException]]+
        • 1. Re: Bug: OEPE 12c JAXB
          Blaise Doughan-Oracle
          You need to ensure that you have correctly added EclipseLink to your class path. EclipseLink can be obtained from the following location:
          - http://www.eclipse.org/eclipselink/downloads/

          -Blaise
          • 2. Re: Bug: OEPE 12c JAXB
            dvohra21
            org.eclipse.persistence.jaxb.JAXBContextFactory is in the \\eclipselink\jlib\eclipselink.jar.


            Implementation class com.sun.xml.bind.v2.runtime.JAXBContextImpl is in the \\eclipselink\jlib\moxy\com.sun.xml.bind_2.2.0.v201004141950.jar.

            com.sun.xml.bind_2.2.0.v201004141950.jar and eclipselink.jar are in the Java Build classpath.
            • 3. Re: Bug: OEPE 12c JAXB
              Blaise Doughan-Oracle
              Can you post the full stack trace?

              Also you do not need com.sun.xml.bind_2.2.0.v201004141950.jar on your class path. It is included in the EclipseLink install because it is a required dependency for the XML Schema to Java Compiler (XJC) utility.

              -Blaise
              • 4. Re: Bug: OEPE 12c JAXB
                dvohra21
                Can you post the full stack trace?
                Already did.

                javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory could not be instantiated: javax.xml.bind.JAXBException
                - with linked exception:
                +[java.lang.NullPointerException]     +
                - with linked exception:
                +[javax.xml.bind.JAXBException+
                - with linked exception:
                +[java.lang.NullPointerException]]+
                • 6. Re: Bug: OEPE 12c JAXB
                  C.Stodden
                  So, in the "full stack trace" are you seeing a duplicate property statement?
                  • 7. Re: Bug: OEPE 12c JAXB
                    dvohra21
                    So, in the "full stack trace" are you seeing a duplicate property statement?
                    No.

                    The JAXB project facet is installed. No other configuration should be required. Eclipse version is 3.7.
                    • 8. Re: Bug: OEPE 12c JAXB
                      dvohra21
                      To test the bug:
                      1. Create a project and add Java class JAXBMarshaller:



                      package jaxb;

                      import javax.xml.bind.*;

                      public class JAXBMarshaller {

                           public static void main(String[] argv) {

                                try {
                                     JAXBContext jaxbContext = JAXBContext.newInstance("jaxb");

                                } catch (JAXBException e) {

                                     System.err.println(e.toString());

                                }
                           }
                      }

                      2. Add jaxb.properties to jaxb package and set
                      javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

                      3. Add the JAXB Project facet to the project.
                      4. Run the Java application

                      Edited by: dvohra16 on Oct 2, 2012 1:36 PM

                      Edited by: dvohra16 on Oct 2, 2012 1:40 PM
                      • 9. Re: Bug: OEPE 12c JAXB
                        C.Stodden
                        Given the following:
                        -JPA Project with Eclipselink 2.4.
                        -Created the JAXBMarshaller Class.
                        -Run->as Java Application
                        -The launch class path contains the EclipseLink 2.4.0 Libraries. As well as the Project Classes.

                        Background:
                        JAXBContext.newinstance("package name"): This makes use of the Thread class loader, so if you are getting exotic you may need to supply your own class loader argument. I didn't have to in this case.

                        Doc:
                        "The JAXBContext instance is initialized from a list of colon separated Java package names. Each java package contains JAXB mapped classes, schema-derived classes and/or user annotated classes. Additionally, the java package may contain JAXB package annotations that must be processed. (see JLS 3rd Edition, Section 7.4.1. Package Annotations). "

                        Exception: (Here is the exception that I saw)
                        javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "jaxb" doesnt contain ObjectFactory.class or jaxb.index     
                        - with linked exception:
                        [javax.xml.bind.JAXBException: "jaxb" doesnt contain ObjectFactory.class or jaxb.index]

                        Getting things working:
                        -Create the jaxb.index text file. This was empty.

                        Edited by: C.Stodden on Oct 3, 2012 10:19 AM
                        • 10. Re: Bug: OEPE 12c JAXB
                          Blaise Doughan-Oracle
                          Below is what I did using the all-in-one EclipseLink 3.8 (Juno) Oracle Enterprise Pack for Eclipse (12.1.1.1.0) for MacOX (64-bit). This can be obtained from the link below.
                          - http://www.oracle.com/technetwork/developer-tools/eclipse/downloads/index.html

                          Create a Plug-in Project

                          1. Created an File | New | Plug-in Project
                          2. Edit the MANIFEST.MF to include a dependency on the org.eclipse.persistence.moxy bundle

                          jaxb/JAXBMarshaller.java
                          package jaxb;
                          
                          import javax.xml.bind.*;
                          
                          public class JAXBMarshaller {
                          
                               public static void main(String[] argv) {
                                    try {
                                         JAXBContext jaxbContext = JAXBContext.newInstance("jaxb");
                                         System.out.println(jaxbContext.getClass());
                                    } catch (JAXBException e) {
                                         System.err.println(e.toString());
                                    }
                               }
                               
                          }
                          jaxb/jaxb.properties

                          To specify MOXy as your JAXB provider you need to include a file called jaxb.properties in the same package as your domain model with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html).
                          javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
                          jaxb/jaxb.index

                          When bootstrapping from a context path you need to have an ObjectFactory class or a jaxb.index file in that package to let your JAXB impl know which classes are mapped. A jaxb.index file is a carriage return separated list of short class names.
                          JAXBMarshaller
                          JAXBMarshaller
                          package jaxb;
                          
                          import javax.xml.bind.*;
                          
                          public class JAXBMarshaller {
                          
                               public static void main(String[] argv) {
                                    try {
                                         JAXBContext jaxbContext = JAXBContext.newInstance("jaxb");
                                         System.out.println(jaxbContext.getClass());
                                    } catch (JAXBException e) {
                                         System.err.println(e.toString());
                                    }
                               }
                               
                          }
                          Output
                          class org.eclipse.persistence.jaxb.JAXBContext
                          • 11. Re: Bug: OEPE 12c JAXB
                            dvohra21
                            Thanks
                            C.Stodden.

                            The xjc compiler does generate ObjectFactory.java. jaxb.index is not required.
                            Tested with a JPA project with EclipseLink and the xjc generated classes get marshalled to an XML document.

                            What is the JAXB project facet for, if JAXB requires a JPA project?
                            • 12. Re: Bug: OEPE 12c JAXB
                              Blaise Doughan-Oracle
                              The JAXB facet was introduced by the [Dali Project|http://www.eclipse.org/webtools/dali/] and is part of the [Web Tools Platform|http://www.eclipse.org/webtools/] . It provides mechanisms to generate Java classes from an XML schema, and also provides validation messages when you are trying to map an object model to an existing schema. It can be added as a facet to any project, or you can create a JAXB project:

                              File | New | Other | JAXB Project

                              When configuring the JAXB project or facet you can choose MOXy as the JAXB provider. To do this you will need to configure a user library that contains the EclipseLink implementation.

                              -Blaise
                              • 13. Re: Bug: OEPE 12c JAXB
                                dvohra21
                                Thanks Blaise. A JAXB Project with EclipseLink user library also does not generate the error posted earlier.

                                The JAXB Classes generated from an XML Schema, when generated with Generate>JAXB Classes in Project Explorer do not include a jaxb.properties file. The JAXB Classes from Schema in New>JAXB does generated the jaxb.properties. Is the jaxb.properties not getting generated with Generate>JAXB Classes a bug?

                                Also, shouldn't a JAXB Project include the EclipseLink library by default? OEPE 11g does not require a EclipseLink library to be configured.

                                Edited by: dvohra16 on Oct 3, 2012 1:12 PM
                                • 14. Re: Bug: OEPE 12c JAXB
                                  Blaise Doughan-Oracle
                                  When EclipseLink is specified as the JAXB platform the proper jaxb.properties file should be generated. Below is what worked for me.

                                  To create a JAXB project in Eclipse you need to do the following:
                                      File | New | Project... | JAXB Project | Next 
                                  JAXB Project Config
                                      Plaform:  EclipseLink 2.1.x
                                      Type:  User Library
                                  The user library you create should contain the following (based on an EclipseLink 2.4.0 install)
                                      <ECLIPSELINK_HOME>/jlib/eclipselink.jar
                                      <ECLIPSELINK_HOME>/jlib/moxy/com.sun.tools.xjc_2.2.0.jar
                                      <ECLIPSELINK_HOME>/jlib/moxy/com.sun.xml.bind_2.2.0.v201004141950.jar
                                  -Blaise