問題描述
我正在生成一個(gè)要放入商業(yè)軟件產(chǎn)品的 jar.該 jar 符合商業(yè)軟件的 api 并依賴于第二個(gè) jar,其中包含(除其他外)一組從 XSD 生成的 POJO.但是,當(dāng)我將它放入時(shí)嘗試實(shí)例化 JAXBContext 時(shí)它會(huì)失敗.
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(為簡(jiǎn)潔起見)如下所示:
My XSD (summarized for brevity) looks like this:
<xsd:schema ... >
<xsd:element name="MyClass" type="myType" />
<xsd:complexType name="myType">
...
</xsd:complextType>
</xsd:schema>
我認(rèn)為問題可能在于xsd:element"級(jí)別的類不存在,但即使我將 XJC 設(shè)置為創(chuàng)建 MyClass 并且我已驗(yàn)證 MyClass 有一個(gè)公共 no-,問題仍然存在arg 構(gòu)造函數(shù).
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.
所以,我已經(jīng)查看了其他幾個(gè) SO 問題(事實(shí)上,在整個(gè)互聯(lián)網(wǎng)上).他們都沒有給我足夠的理解來解決這個(gè)問題,這可能只是對(duì)我的一個(gè)不好的反映.任何人都可以提供一些見解嗎?或者給我做其他測(cè)試來解決這個(gè)問題?
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?
推薦答案
最終這個(gè)問題是由已修復(fù)的錯(cuò)誤引起的.我正在加載的系統(tǒng)使用庫(kù) JAXB-2.0,我認(rèn)為我使用的是最新版本 (JAXB-2.2.5).由于設(shè)計(jì)不佳的插件框架,我的版本被 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.
為了解決這個(gè)問題,我必須升級(jí)商業(yè)軟件的庫(kù),或者嘗試使用 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
感謝所有幫助我找到這個(gè)的人.
Thanks to everyone who helped me to find this.
這篇關(guān)于什么可能導(dǎo)致“JAXBElement 沒有無參數(shù)默認(rèn)構(gòu)造函數(shù)"?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!