Search code examples
javajaxbclassloader

Help with creating a new JAXB instance in Oracle enterprise manager


When trying to create a new JAXB instance inside a servlet I am getting a JAXBException saying the jaxb.properties cannot be found. I have been trying to explicitly pass the classloader with the call to JAXBContext.newInstance() but I cannot figure it out.

Here are the class loaders:

servlet classloader:    oc4j:10.1.3  
servlet parent classloader:     api:1.4.0  
this classloader:   RestTest.web.ExampleWebApp:0.0.0  
this classloader parent: RestTest.root:0.0.0   

The JAXB generated classes are in a different package, so my servlet is in package "com.xyz.ws" and the JAXB classes are in package "com.abc.123". I am creating the new JAXB instance from the servlet with `

JAXBContext.newInstance("com.abc.123", servletClassLoader)

(I also tried using this.getClass().getClassLoader())


Solution

  • It seems this fixes the issue (found here):

    Step 1 : Copy the JAXB2.0 jars to D:\dev\oc4j10.1.3.0.0\j2ee\home\applib (D:\dev\oc4j10.1.3.0.0 is my oc4j installation location) (j2ee\home\applib This directory is placeholder for common library files for all projects (deployed applications) Files which were added were jaxb-api-2.0.jar, jaxb-impl-2.0.jar, jsr173_api-1.0.jar (JAXB2.0 jars can be found at http://jaxb.java.net/)

    Step2: When deploying Application via Enterprise Manager (WebBrowser) change the deployment plan.

    2.1 You can change deplyoment plan on the last step (screen) of depolyment by clicking on a BUTTON saying Edit Deployment plan.

    2.2 On clicking the BUTTON Application sepcific properties are displayed. Select link importedLibraries (Edit importedLibraries) and then CLICK Edit Remove link enter name oracle.xml and click continue and finish the deployment.

    The reason of the error is xml.jar (JAXB 1.0) which is present as shared libaray in variable name oracle.xml (see Enterprise Manager->Administration-> Shared Libraries.

    What we achieved from above steps is removing default (old version of JAXB) for our application and forcing OC4J to read newer JAXB2.0 implementation (jars)