JAXBException on creating JAXB Context

北战南征 提交于 2019-12-05 08:09:17

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?

Kefirchiks

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

ag112

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

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!