开发者

Cannot get EclipseLink MOXy to work

I'm new to JAXB and I want to change the default namespace prefix using EclipseLink MOXy. My package-info.java has the following code lines:

@javax.xml.bind.annotation.XmlSchema (
namespace="http://namespace.mysite.com/",
xmlns = { 
    @javax.xml.bind.annotation.XmlNs(prefix="myns", 
               namespaceURI="http://namespace.mysite.com/")
},
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED
)
package com.core.mymodel;

And my jaxb.properties file has the following line:

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

I have added eclipselink.jar to the CLASSPATH, both package-info.java and jaxb.properties files are in the same package as my model classes, however, when I run the program I get the following error message:

javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory        not found
- with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Un开发者_开发问答known Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)

I have tried this with EclipseLink versions 2.3.0 and 2.0.2 and still got the same error message. Does anyone happen to know what could be the problem?

Many thanks in advance


You appear to have your jaxb.properties file correct based on the exception message:

javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory        not found
- with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)

To confirm that org.eclipse.persistence.jaxb.JAXBContextFactory is on your classpath can you try:

JAXBContext jc = JAXBContextFactory.createContext("com.core.mymodel", null);

To do a more basic confirmation can you run:

System.out.println(org.eclipse.persistence.Version.getVersion());

For More Information

  • http://bdoughan.blogspot.com/2011/05/specifying-eclipselink-moxy-as-your.html


Use it as a System property

System.setProperty("javax.xml.bind.JAXBContextFactory", "org.eclipse.persistence.jaxb.JAXBContextFactory");


Simply specify the JAXBContext explicitly:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜