我正在生成一个要放入商业软件产品的 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 有一个公共 no-,问题仍然存在arg 构造函数.
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.
为了解决这个问题,我必须升级商业软件的库,或者尝试使用 Classloaders
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 没有无参数默认构造函数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!