xml – 无法使EclipseLink MOXy工作

我是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并仍然得到相同的错误消息.有谁碰巧知道可能是什么问题?

提前谢谢了

最佳答案
您似乎根据异常消息使您的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());

欲获得更多信息

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

转载注明原文:xml – 无法使EclipseLink MOXy工作 - 代码日志