无法让 EclipseLink MOXy 工作

发布于 2024-11-26 08:35:19 字数 1281 浏览 1 评论 0原文

我是 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 尝试过此操作,但仍然收到相同的错误消息。有谁知道可能是什么问题吗?

预先非常感谢

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(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)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤者何惧 2024-12-03 08:35:19

根据异常消息,您的 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());

了解更多信息

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

淡淡の花香 2024-12-03 08:35:19

只需显式指定 JAXBContext:

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

Simply specify the JAXBContext explicitly:

JAXBContext jaxbContext = org.eclipse.persistence.jaxb.JAXBContextFactory
                .createContext(new Class[] {YourClass.class}, null);
仅一夜美梦 2024-12-03 08:35:19

将其用作系统属性

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

Use it as a System property

System.setProperty("javax.xml.bind.JAXBContextFactory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文