質問

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.

I get:

"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"); 
    ...

My XSD (summarized for brevity) looks like this:

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

</xsd:schema>

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, 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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top