Thursday, April 28, 2011

Is there a problem initializing a JAXBContext with a package in a library?

I'm trying to initialize a JAXBContext like so:

JAXBContext jaxbContext = JAXBContext.newInstance("ebay.apis.eblbasecomponents");

When the code is run, however, I get the following run time error:

Exception in thread "main" java.lang.NoClassDefFoundError: ebay/apis/eblbasecomponents/ObjectFactory
Caused by: java.lang.ClassNotFoundException: ebay.apis.eblbasecomponents.ObjectFactory

The ebay.apis.eblbasecomponents package is in a library that the initialization code has access to. The ObjectFactory class IS in that package. I actuall ran it like this to make sure:

    ebay.apis.eblbasecomponents.ObjectFactory factory = new ObjectFactory();
    JAXBContext jaxbContext = JAXBContext.newInstance("ebay.apis.eblbasecomponents");

I'm not an experienced Java developer, so I'm not even really sure what might be the problem at this point, other than it can't seem to find a class that is obviously there. I have done a clean and build on the library that has the package in question, and that works just fine. I thought I would ask for help on here while I continue poking around trying to figure this out.

From stackoverflow
  • OK, well I moved the package out of the library it was in and directly into the project that was trying to access it (so it can access the package directly instead of having to do it through the library) and it seems to be working now. Hopefully someone will have a better answer or solution explaining why this is, but for now at least the project isn't blowing up on me.


Post a Comment