什么可能导致“JAXBElement没有no-arg默认构造函数”? [英] What might cause "JAXBElement Does not have a no-arg default constructor"?

查看:493
本文介绍了什么可能导致“JAXBElement没有no-arg默认构造函数”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个将被放入商业软件产品中的jar。该jar符合商业软件的api,并依赖于第二个jar,其中包含(除其他外)从XSD生成的一组POJO。但是,当我将它放入时,尝试实例化JAXBContext时失败。

I'm generating a jar which is to be dropped into a commercial software product. That jar conforms to the commercial software's api and depends on a second jar, which contains (among other things) a set of POJOs generated from an XSD. However, it fails when trying to instantiate JAXBContext when I drop it in.

我得到:

"1 counts of IllegalAnnotationExceptions"
javax.xml.bind.JAXBElement does not have a no-arg default constructor.
  this problem is related to the following location: 
    at javax.xml.bind.JAXBElement
    at mypackage.MyClass
    ...
    JAXBContext.newInstance("mypackage"); 
    ...

我的XSD(简洁总结)如下所示:

My XSD (summarized for brevity) looks like this:

<xsd:schema ... >
  <xsd:element name="MyClass" type="myType" />
  <xsd:complexType name="myType">
  ...
  </xsd:complextType>

</xsd:schema>

我想也许问题是xsd:element级别的类不存在但是,即使我将XJC设置为创建MyClass并且我已经验证MyClass有一个公共的无参数构造函数,问题仍然存在。

I thought perhaps that the issue was that Classes at the "xsd:element" level didn't exist, but the problem persists even when I set XJC up to create MyClass and I've verified that MyClass has a public no-arg constructor.

所以,我看了几个其他的SO问题(实际上是整个互联网)。他们都没有给我足够的理解来解决这个问题,这可能只是对我的反思。任何人都能有所了解吗?或者给我一些替代测试来解决这个问题?

So, I've looked at several other SO questions (and all over the internet, in fact). None of them gave me enough understanding to solve this problem, which may just be a poor reflection on me. Can anybody shed some insight? Or give me alternative tests to conduct to break this down?

推荐答案

最终这个问题是由一个已修复的错误引起的。我加载的系统使用库JAXB-2.0,我认为我使用的是最新版本(JAXB-2.2.5)。由于设计糟糕的插件框架,我的版本被2.0 jar抢占了。

Ultimately this problem was caused by an error that has been fixed. The system I am loading into uses the library JAXB-2.0 where I thought I was using the latest version (JAXB-2.2.5). Thanks to a poorly designed plugin framework, my version was being pre-empted by the 2.0 jar.

为了超越这个,我将不得不升级库商业软件,或尝试使用类加载器

In order to get past this I'll have to either upgrade the library of the commercial software, or try and play with Classloaders

感谢所有帮助我找到这个的人。

Thanks to everyone who helped me to find this.

这篇关于什么可能导致“JAXBElement没有no-arg默认构造函数”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆