Mule JaxB binding error - "package" doesnt contain ObjectFactory.class or jaxb.index

1.7k views Asked by At

I am using mule with maven. I have used a xml to object converter. My model files are annotated with jaxb annotations. The JAXB context ref looks like this -:

mulexml:jaxb-context name="JAXB_Context" packageNames="com.xml.model" doc:name="JAXB Context"/>

I have created a jaxb.index file with the names of the JAXB annotated classes and placed in the com.xml.model folder.

But still it shows the following exception -:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_muleNotificationManager': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JAXB_Context': Invocation of init method failed; nested exception is javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.xml.model" doesnt contain ObjectFactory.class or jaxb.index - with linked exception: [javax.xml.bind.JAXBException: "com.xml.model" doesnt contain ObjectFactory.class or jaxb.index]

This has worked for the mule project without maven.

3

There are 3 answers

1
Arup Mishra On BEST ANSWER

I have found the solution for it. We need to keep the jaxb.index file in the resources folder with the same package structure.

I think when using Maven, it doesn't pick the file from the package. It uses its own build methods, but when used without Maven the build is done by Anypoint studio's own build methods and so it gets the jaxb file.

2
Ralph Rimorin On

Arup, can you check whether the zip file or the jar file containing the package/classes com.xml.model.* exist. That means that the project wasn't able to see those in the generated compressed file by maven.

0
Striker On

Here is how I got it to work with jaxb.index

Say, all you marshalling classes like Order, Customer, Merchant are located in package com.common.beans

  1. Your flow xml Jaxb-Context will be configured pointing to that package: <mulexml:jaxb-context name="JAXB_Context" packageNames="com.common.beans" doc:name="JAXB Context"/>

  2. Inside com.common.beans package create a file jaxb.index with content of your marshalling classes as follows on each line:

Order

Customer

Merchant

The Error should go away.

Enjoy! :)