- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个非常简单的 Eclipse 插件,它使用 EclipseLink 的 MOXy 进行 XML 绑定(bind)(编码/解码)。当我在插件 (Activator.java) 的启动过程中尝试编码一个简单的类 (Person.java) 时,我遇到了一些错误。这是代码:
Person.java
package test_rcp;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Activator.java
package test_rcp;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// Just to make sure EclipseLink is already loaded
System.out.println(org.eclipse.persistence.Version.getVersion());
Person p1 = new Person();
p1.setName("John Dewey");
p1.setAge(54);
JAXBContext jc = JAXBContext.newInstance("test_rcp",Person.class.getClassLoader());
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(p1, System.out);
}
}
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test-RCP
Bundle-SymbolicName: Test-RCP; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: test_rcp.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.persistence.core,
org.eclipse.persistence.moxy;bundle-version="2.4.1"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
包 test_rcp
还包含 jaxb.index
和 jaxb.properties
:
jaxb.index
Person
jaxb.properties
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
但是运行插件会抛出以下异常:
javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory could not be instantiated:
javax.xml.bind.JAXBException: Provider class org.eclipse.persistence.jaxb.JAXBContextFactory could not be instantiated:
javax.xml.bind.JAXBException:
ClassCastException: attempting to cast bundleresource://43.fwk583158213/javax/xml/bind/JAXBContext.class to jar:file:/usr/lib/jvm/java-7-oracle/jre/lib/rt.jar!/javax/xml/bind/JAXBContext.class. Please make sure that you are specifying the proper ClassLoader.
我知道问题是因为两个类加载器加载了 javax.xml.bind
包,但我不知道为什么以及如何避免这种情况。
此外,通过使用 JAXBContextFactory
而不是 JAXBContext.newInstance
(建议 here ),即:
JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {Person.class}, null);
我会得到以下异常:
java.lang.LinkageError: loader constraint violation:
loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously
initiated loading for a different type with name "javax/xml/bind/JAXBContext"
我已经尝试过以下解决方案但没有成功:
https://stackoverflow.com/a/12943115/2295964
https://stackoverflow.com/a/11797373/2295964
如果有人能帮助我摆脱这种痛苦,我将不胜感激!
最佳答案
您发布的 list 仅包含Require-Bundle
:
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.persistence.core,
org.eclipse.persistence.moxy;bundle-version="2.4.1"
我建议将 Import-Package: javax.xml.bind
添加到 bundle list 中。这应该允许框架将包解析为 org.eclipse.persistence.moxy
使用的包。
关于java - EclipseLink MOXy OSGi 包的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16121374/
我在嵌入式 Jetty 9.x 服务器内使用 Jersey 2.x 和内置的 MOXy 转换从 JSONPOJO。 是否可以以编程方式(在 POJO 上没有注释)为特定类型(例如 Joda DateT
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
Moxie看起来很驼鹿,但标题信息量不大, Moxie - Not Another Moose Clone 看了一下,好像用了 B::CompilerPhase::Hook 额外的伏都教。这个库的最终
我有一个基类声明如下: package com.mystuff.surrogates; import java.io.Serializable; import java.util.UUID; publ
我正在使用 MOXy 2.5.1 以及 Jersey 2.4 和 Hibernate。我发现 MOXy 与一组特定的类有奇怪的编码行为。 我有一些与此类似的类(为简洁起见,删除了其他内容): publ
我正在使用 MOXy 来解码一个相对简单的 XML 文档,但我得到了不一致的行为。该文档由两个元素组成,其中包含基本信息(名称和日期),后跟记录列表。问题是名称和日期每次都正确解码,但是我经常得不到任
我按照指示here进行操作为了为我的带注释的类生成 XML 架构。我使用 MOXy 作为 JAXB 的底层实现,因为我需要它的某些功能,例如 @XmlPath 以及它如何处理 XmlAdapter 的
是否可以根据某些运行时信息有条件地仅输出元素(作为 XML 或 JSON)? 我自己找到了答案,并想与大家分享。 最佳答案 简单: return null 示例 我有一个列表“alertStems”和
我有一个非常简单的类,有两个字段,String sourceAddress 和 int port。 我希望它们映射到源/地址和源/端口节点而不是 jaxb 默认的 sourceAddress 和 so
使用EclipseLink MOXy JAXB实现,我试图使用@XmlPath批注基于元素的属性值获取元素值。我似乎无法正常工作。支持吗? XML摘录: ... 12345 blah POJO
我使用 moxy 来构建大型结构,在 95% 的情况下,它的效果就像 charme 一样。它快速且可靠。但我现在确实有一个具有相同类结构但数据不同的项目。现在我确实产生了很大的阅读影响。写完整的项目大
为了解决另一个问题,我已从使用 Jersey 转向使用 EclipseLink MOXy 从 JAXB 创建的对象模型(由 Sun JAXB 2.1.12 创建)生成 JSON。我注意到的一个区别是输
我有一个相当大的对象树,我想将其导出为 XML。名为 Person 的对象在多个地方使用(作为许多子实体的 userCreated、userModified、作为客户端等) 根据 Person 对象的
我正在使用 JAXB/MOXy 解码一个包含大约 50 个此类对象的 XML 文件: @XmlRootElement(name="Message") public class MyClass{ pri
我有一个使用 Jersey 和 MOXy 的 JAX-RS 服务。我有一个返回类型 Memo 的 JSON 或 XML(取决于 Accept: header )表示的处理程序,但如果找不到该项目,它应
我试图找到包含等同于 的类的 Maven 依赖项 import org.eclipse.persistence.oxm.annotations.XmlVariableNode; 这是我目前拥有的 PO
我正在定义一个静态工厂方法: @XmlType(factoryClass=DummyFactory.class, factoryMethod="createNew") public abstract
我的问题是 this 的后续问题评论。 我在同一个类上混合使用 JPA 和 JAXB (MOXy) 注释,大多数情况下效果很好。如链接线程中所述,@XmlInverseReference 在编码双向关
我似乎无法让@XmlCData 注释起作用,即使 MOXy 已正确设置。 我的代码,attached , 输出: 1
我正在编写一段代码,使用 MOXy 在运行时设置 XmlTransient。以下是改编自 http://blog.bdoughan.com/2011/06/moxy-extensible-models
我是一名优秀的程序员,十分优秀!