| Location of jaxb.index for JAXB [message #911626] |
Tue, 11 September 2012 21:59  |
John Raspet Messages: 3 Registered: September 2012 |
Junior Member |
|
|
Hi,
I'm creating a JAXBContext as follows:
JAXBContext.newInstance("my.package");
and when I put the jaxb.index in "my.package", all is well.
I wish to store jaxb.index in the root of my project and I attempt to create the JAXBContext like this:
JAXBContext.newInstance(".");
I place the jaxb.index file in the root of the project (if possible, I would prefer to store it in src/main/resources). This causes a JAXBException stating the jaxb.index file could not be found.
What am I doing wrong? How can I define a custom path to the jaxb.index file?
|
|
|
|
|
| Re: Location of jaxb.index for JAXB [message #912442 is a reply to message #911626] |
Thu, 13 September 2012 11:40   |
Blaise Doughan Messages: 131 Registered: July 2009 |
Senior Member |

|
|
Hi John,
I'm happy to hear that you have found my blog, and answers on Stack Overflow helpful.
Standard JAXB Approach
The jaxb.index file needs to be in the same package as the classes it references. If you have classes in different packages then you could have a jaxb.index file per package.
What You Could Do
If the standard JAXB approach doesn't meet your requirements you could introduce your own config file, and then perform your own processing to convert the contents of that file to a Class[]. Then you could bootstrap a JAXBContext from that Class[].
-Blaise
[Updated on: Thu, 13 September 2012 13:36] Report message to a moderator
|
|
|
| Re: Location of jaxb.index for JAXB [message #917012 is a reply to message #912442] |
Wed, 19 September 2012 14:30   |
John Raspet Messages: 3 Registered: September 2012 |
Junior Member |
|
|
Blaise Doughan wrote on Thu, 13 September 2012 11:40
If the standard JAXB approach doesn't meet your requirements you could introduce your own config file, and then perform your own processing to convert the contents of that file to a Class[]. Then you could bootstrap a JAXBContext from that Class[].
-Blaise
Blaise,
I'm attempting to pursue the solution quoted above as it seems like a good alternative. One hurdle I'm facing is using
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
I used to have this in my jaxb.properties file, but since I am no longer using a context path, I attempted to specify this property by using:
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
Class<?>[] classes;
// ... load classes ...
JAXBContext jaxbContext = JAXBContext.newInstance(classes, properties);
and the result is:
javax.xml.bind.JAXBException: property "javax.xml.bind.context.factory" is not supported
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
Any insight on how to continue using org.eclipse.persistence.jaxb.JAXBContextFactory when loading the classes from a file?
EDIT:
Scratch that, found another of your answers on SO that might work. I can't seem to link it since I have fewer than 25 messages, but for anyone else that might stumble on this issue, a quick google search for 6963996/can-i-replace-jaxb-properties-with-code should find the thread.
[Updated on: Thu, 20 September 2012 12:34] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.01748 seconds