Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Location of jaxb.index for JAXB
Location of jaxb.index for JAXB [message #911626] Wed, 12 September 2012 01:59 Go to next message
John Raspet is currently offline John RaspetFriend
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 #911909 is a reply to message #911626] Wed, 12 September 2012 15:08 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi John,

The context path used to create a JAXBContext must be a valid package name. Your JAXB (JSR-222) implementation will look for a jaxb.index file there. The file itself is a carriage return separated list of classes that belong to that package.

-Blaise
Re: Location of jaxb.index for JAXB [message #911997 is a reply to message #911909] Wed, 12 September 2012 18:48 Go to previous messageGo to next message
John Raspet is currently offline John RaspetFriend
Messages: 3
Registered: September 2012
Junior Member
Hello Blaise,

Thank you for your response. I feel obligated to thank you for your handful of responses on SO and for your blog as well, it has been immensely helpful Smile.

Getting back to the topic: Is there a valid package name that would point to the root of the project?

e.g.

If I only have one package called "package," is there a way I can have the jaxb.index one directory above this folder? The limitation that occurs is that any annotated class that I want to list in the jaxb.index file then must be in the "package" package. I want to be able to have annotated classes outside this package without having to create a common parent package.
Re: Location of jaxb.index for JAXB [message #912442 is a reply to message #911626] Thu, 13 September 2012 15:40 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
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 17: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 18:30 Go to previous messageGo to next message
John Raspet is currently offline John RaspetFriend
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 16:34]

Report message to a moderator

Re: Location of jaxb.index for JAXB [message #919217 is a reply to message #911626] Fri, 21 September 2012 20:04 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Here is the link that John mentioned in his post:

http://stackoverflow.com/questions/6963996/can-i-replace-jaxb-properties-with-code

It describes how you can use the native MOXy APIs to create a JAXBContext:

JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {Animals.class}, null);

-Blaise

Previous Topic:Large network traffic in comparission to SQL-Developer
Next Topic:NPE in MethodAttributeAccessor.getAttributeValueFromObject()
Goto Forum:
  


Current Time: Tue Dec 23 04:36:06 GMT 2014

Powered by FUDForum. Page generated in 0.06099 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software