JAXBException on creating JAXB Context
Asked Answered
B

5

6

When I run application as standalone Java program, it works well. When I run it as an applet, it throws JAXBException with following stacktrace.

javax.xml.bind.JAXBException: jaxb.properties in package com/test/package does not contain the javax.xml.bind.context.factory property.
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)

When I add a jaxb.properties, i get the below error -

javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.NoSuchMethodException: com.sun.xml.internal.ws.developer.JAXBContextFactory.createContext([Ljava.lang.Class;, java.util.Map)]
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    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)

I added following jars to classpath -

  • jaxws-rt-2.2.1
  • jsr311-api-1.1.1
  • jersey-core-1.2
  • jersey-client-1.2

What causes this error. Am I missing any dependencies.

Edit: I am using Java 7 u 59 on both browser and development environment.

Bountiful answered 28/8, 2015 at 10:28 Comment(1)
Looks like you libs are not compatible.Tronna
L
0

Jersey version 1.2 seems outdated. I think Jersey 2.21 is the current version. Furthermore, you should inspect which JDK/JRE you are using to run your program. Does the applet run in the same environment/Java version as when you start it as an application?

Leaseholder answered 28/8, 2015 at 11:2 Comment(0)
S
0

First, you need to check are you using the same JRE. You can do that here. And as @LarsGendner mentioned - download JAXB 2.2.* jar, because 1.2 is outdated.

Second: Check out this topic: How can I use JAXB from an unsigned applet (without signing it)?

Sternlight answered 31/8, 2015 at 10:57 Comment(0)
E
0

Based on your information provided, here are my inputs. Please note anything which require your input/you-to-try-out, I have marked it as <try-out>.

Firstly <try-out> following:

a. Verify you don't see multiple java versions as checked inside: widnows-> control panel->java->java tab->view java locations. Basically this is to ensure your java application and applet using same JRE.

Regarding your first exception : javax.xml.bind.JAXBException: jaxb.properties in package com/test/package does not contain the javax.xml.bind.context.factory property

This is problem of JRE not able to locate an JAXB implementation. Please go through the URL and locate section "Discovery of JAXB implementation". It mentions that following 4 locations are used to identify JAXB implementation:

  1. Finding jaxb.properties at package level directory
  2. System property JAXB_CONTEXT_FACTORY
  3. Looking for /META-INF/services/javax.xml.bind.JAXBContext file in all jars
  4. Default JVM specific implementation.

Now you are getting this exception only in case of Applet NOT for JAVA application. You mentioned that both java application and applet are using same JDK + additional jars. Only reason I can think of difference between applet and application environment could be due to point 2 above.

<try-out> following:

b.Can you check if you are specifying JAXB_CONTEXT_FACTORY as system property when you run java application (perhaps through eclipse or something)

c. May be you can print all system properties in your code:

Properties props = System.getProperties();
props.list(System.out);

and verify if JAXB context factory is set there or not?

Regarding your second exception : after you added jaxb.properties file, you received your second exception. It could be due to following reason:- exception stack trace shows you might have specified com.sun.xml.internal.ws.developer.JAXBContextFactory in JAXB.properties file. Now if you see again URL and locate first SPEC REQUIREMENT for JAXBContext provider: the provider must supply an implementation class containing the following method signatures:

public static JAXBContext createContext( Class[] classes, Map<String,Object> properties ) throws JAXBException

Further Now if you google content of com.sun.xml.internal.ws.developer.JAXBContextFactory class, you can see at this site that this class does NOT contain the method createConext(); it only define a method call createJAXBContext(). Please note this class is internally called by com.sun.xml.internal.bind.api.JAXBRIContext which extension of javax.xml.bind.JAXBContext class.

<try-out> following:

d. you should specify a proper value of javax.xml.bind.context.factory in jaxb.properties file which point to a class implementing createConext() operation.

Finally, last point : There is possiblity that you are specifying correct factory in jaxb.properties but its value might not be picked by runtime and instead runtime is picking JAXB implementation value from other mechanisms specified in points 1-4 above. This can be case of multiple JAXB factory implementations present in JVM runtime.

<try-out> following:

e. In such situations, best to use Java endorsed override mechanism as specified in this post

Erlene answered 1/9, 2015 at 14:33 Comment(1)
@ACN: could you please let me know did you try out the options I had provided-what worked for you? This would help others too perhaps.Erlene
Y
0

From the exception i came to know that your WS is referring to the java rt.jar and not referring to the jar added by you in the classpath.

So from this i can conclude the jar is not placed exactly in the classPath.

Yann answered 2/9, 2015 at 19:11 Comment(0)
V
0

Second Exception: Check the class getting referred from which jar and replace the proper jar file which has createjaxbcontext method.

Use the proper version of jar in the classpath(jaxws-rt).

Venule answered 6/9, 2015 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.