Results 1 to 2 of 2
  1. #1
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Rep Power

    Question Not sure what error means? javax.xml.bind.JAVAXBException

    Hi all!

    I have compiled several .java files into .class files with no errors. All of the .java source files are located in my working directory and i unpacked any .jar's that were provided into the same directory prior to compiling, so all dependency imports should be present.

    When i attempt to run my .class file, i get errors and i'm having a hard time understanding what they mean.

    Can someone help point me in the right direction? Thanks so much for any info!

    Java Code:
    C:\java_test>java -classpath . com.amazonservices.mws.sellers.samples.GetService
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at com.amazonservices.mws.sellers.MarketplaceWebServiceSellersClient.<cl
            at com.amazonservices.mws.sellers.samples.GetServiceStatusSample.main(Ge
    Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.C
    ontextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.amaz
    onservices.mws.sellers.model" doesnt contain ObjectFactory.class or jaxb.index
     - with linked exception:
    [javax.xml.bind.JAXBException: "com.amazonservices.mws.sellers.model" doesnt con
    tain ObjectFactory.class or jaxb.index]
            at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
            at javax.xml.bind.ContextFinder.find(Unknown Source)
            at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
            at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
            at com.amazonservices.mws.sellers.MarketplaceWebServiceSellersClient.<cl
            ... 1 more
    Caused by: javax.xml.bind.JAXBException: "com.amazonservices.mws.sellers.model"
    doesnt contain ObjectFactory.class or jaxb.index
            at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Sou
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
            ... 6 more

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: Not sure what error means? javax.xml.bind.JAVAXBException

    I think i narrowed this down to these lines:

    Java Code:
    /** Initialize JAXBContext and Unmarshaller **/
    	static {
    		try {
    			jaxbContext = JAXBContext.newInstance(
    		} catch (JAXBException ex) {
    			throw new ExceptionInInitializerError(ex);
    		unmarshaller = new ThreadLocal<Unmarshaller>() {
    			protected synchronized Unmarshaller initialValue() {
    				try {
    					return jaxbContext.createUnmarshaller();
    				} catch (JAXBException e) {
    					throw new ExceptionInInitializerError(e);
    but am unsure if i'm correct. From my understanding, this error is related to the wrong class loader being used?

    14 down vote accepted

    OK, this took quite some digging, but the answer is not that surprising and not even that complicated:

    JAXB can't find jaxb.index, because by default, newInstance(String) uses the current thread's class loader (as returned by Thread.getContextClassLoader()). This doesn't work inside Felix, because the OSGi bundles and the framework's threads have separate class loaders.

    The solution is to get a suitable class loader from somewhere and use newInstance(String, ClassLoader). I got a suitable class loader from one of the classes in the package that contains jaxb.index, a sensible choice for flexibility reasons probably is ObjectFactory:

    ClassLoader cl = ();
    JAXBContext jc = JAXBContext.newInstance("", cl);

    Maybe you could also get at the class loader that the Bundle instance is using, but I couldn't figure out how, and the above solution seems safe to me.
    found this answer on but I cna't figure out how to implement this change into my program. From this, it makes be believe my program is unable to locate a jaxb.index file? and that to fix this I need to adjust the code so it looks to the correct class? Can someone help me interpret this error correctly so i can make the necessary changes!

    Thanks so much!

Similar Threads

  1. import*; - error
    By artemff in forum CLDC and MIDP
    Replies: 6
    Last Post: 01-06-2013, 03:58 PM
  2. Error in Javax.Swing.ImageIcon
    By in forum Advanced Java
    Replies: 7
    Last Post: 01-28-2012, 12:14 PM
  3. Replies: 1
    Last Post: 06-14-2011, 12:26 PM
  4. what does this error means?
    By tiiim83 in forum New To Java
    Replies: 2
    Last Post: 01-06-2009, 03:17 PM
  5. Does anyone know what these error means?
    By minifish in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts