問題描述
我正在生成一個要放入商業軟件產品的 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模板網!