我是JAXB的新手,我想使用EclipseLink MOXy更改默认的名称空间前缀。我的package-info.java包含以下代码行:
@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;
我的jaxb.properties文件包含以下行:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
我已将eclipselink.jar添加到CLASSPATH,package-info.java和jaxb.properties文件与我的模型类位于同一个包中,但是,当我运行该程序时,我收到以下错误消息:
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)
我已经使用EclipseLink版本2.3.0和2.0.2尝试了这一点,但仍然收到相同的错误消息。有没有人碰巧知道可能是什么问题?
非常感谢提前
答案 0 :(得分:4)
根据异常消息,您的jaxb.properties
文件似乎正确无误:
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)
要确认您的类路径中有org.eclipse.persistence.jaxb.JAXBContextFactory
,您可以尝试:
JAXBContext jc = JAXBContextFactory.createContext("com.core.mymodel", null);
要进行更基本的确认,您可以运行:
System.out.println(org.eclipse.persistence.Version.getVersion());
了解更多信息
答案 1 :(得分:0)
将其用作系统属性
System.setProperty("javax.xml.bind.JAXBContextFactory", "org.eclipse.persistence.jaxb.JAXBContextFactory");