4

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?

InfernalRapture
  • 572
  • 7
  • 19
  • Unfortunately the true source code is locked up on my company's intranet. Which is why I drop a full recreation here. – InfernalRapture Oct 28 '13 at 18:52
  • Is this how you create JAXBContext `JAXBContext.newInstance("mypackage");`? Try using a generated ObjectFactory class. I had a number of random exceptions when trying to use package method. Also it's a refactoring nightmare unless you derive package name on runtime. – Piotr Gwiazda Oct 28 '13 at 19:12
  • Are you running in an OSGi environment? – bdoughan Oct 28 '13 at 20:04
  • @PiotrGwiazda I have tried both methods at this point, they behave in the same manner. – InfernalRapture Oct 28 '13 at 20:41
  • @BlaiseDoughan It appears to be built off of Eclipse in some shape or form, and Eclipse is most definitely built off of OSGi. – InfernalRapture Oct 28 '13 at 21:16
  • In your manifest make sure to import the `javax.xml.bind` and `javax.xml.bind.annotation` packages. – bdoughan Oct 28 '13 at 21:23
  • @BlaiseDoughan I think I mispoke. I don't have a Manifest to edit. I'm just dropping a jar into ./ext/libs and it should pick it up. – InfernalRapture Oct 29 '13 at 15:58
  • I experienced this error when running a JUnit test via Eclipse, but did not get the error when running the same test via Maven. As with your issue I think this is due to classloading differences between Maven and Eclipse. – eebbesen Feb 18 '14 at 17:03

1 Answers1

3

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.

InfernalRapture
  • 572
  • 7
  • 19