JAXB problems under Java 7 say it cannot find RI 2.1.0

I am running a test on Ubuntu with an update to Oracle Java 7 3. According to the release notes, it includes JAXB-2.2.4.

/home/ubuntu# update-alternatives --config java There is only one alternative in link group java: /usr/lib/jvm/java-7-oracle/bin/java Nothing to configure. 

The machine says that it has JAXB-2.2.4:

 $ wsimport -version JAX-WS RI 2.2.4-b01 

$ java -version

 java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b04) Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode) 

However, when I run my application that uses JAX-RS and marshalls some objects with JAXB, I get the following error:

 Apr 05, 2012 10:45:50 AM com.sun.jersey.api.json.JSONConfiguration natural SEVERE: NATURAL JSON notation configured, but JAXB RI 2.1.10 not found. For the recent builds to get this working correctly, you need even at least JAXB version 2.1.12. Please add it to your classpath! Apr 05, 2012 10:45:50 AM com.sun.jersey.core.spi.component.ProviderFactory __get ComponentProvider SEVERE: The provider class, class com.marketchorus.rest.config.JAXBContextResolv er, could not be instantiated. Processing will continue but the class will not b e utilized java.lang.RuntimeException: NATURAL JSON notation configured, but JAXB RI 2.1.10 not found. For the recent builds to get this working correctly, you need even a t least JAXB version 2.1.12. Please add it to your classpath! 

On the server side, I got the same error, so I installed meto-2.2-standalone in tomcat, which fixed the problem. (Although it worked in java 7).

On a Windows client, I was forced to add JAXB-2.2.5 api, impl and jsr173 jars to my approved java directory in order to make it work (with Java 7 update 3 there too).

When I try to perform a jaxb trick under ubuntu, I put the files in / usr / lib / jvm / java -7-oracle / jre / lib / endorsed. I get another error:

 ERROR 10:55:44.694 taskScheduler-1 org.springframework.scheduling.support.TaskUt ils$LoggingErrorHandler - Unexpected error occurred in scheduled task. javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParser Factory not found 

I initialize the JAX-RS / JAXB code in my class as follows:

 config = new DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); config.getClasses().add(JAXBContextResolver.class); client = Client.create(config); service = client.resource(UriBuilder.fromUri(proc.getUrl()).build()); 

I tried to compile it with source = 1.7 and target = 1.7, as it was still installed for 1.6, and I thought that maybe it was assuming the old version from earlier versions 1.6, which was too old, but that doesnโ€™t solve problem problem.

I ran the @andih test program and I still get the error. I am starting to think that this is a VM problem:

 ubuntu@ip-10-202-155-29 :~/test$ java -cp jersey-client-1.12.jar:jersey-core-1.1 2.jar:jersery-fastinfoset-1.12.jar:jersey-json-1.12.jar:. TestNaturalJson Apr 23, 2012 10:17:21 AM com.sun.jersey.api.json.JSONConfiguration natural SEVERE: NATURAL JSON notation configured, but JAXB RI 2.1.10 not found. For the recent builds to get this working correctly, you need even at least JAXB version 2.1.12. Please add it to your classpath! Exception in thread "main" java.lang.RuntimeException: NATURAL JSON notation con figured, but JAXB RI 2.1.10 not found. For the recent builds to get this working correctly, you need even at least JAXB version 2.1.12. Please add it to your cl asspath! at com.sun.jersey.api.json.JSONConfiguration.natural(JSONConfiguration.j ava:447) at TestNaturalJson.main(TestNaturalJson.java:6) ubuntu@ip-10-202-155-29 :~/test$ java -version java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b04) Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode) 

Looking back at the approved solution with JAXB-2.2.5 RI, I installed the files:

 jaxb-api.jar jaxb-impl.jar jsr173_1.0_api.jar 

in:

 /usr/lib/jvm/java-7-oracle/jre/lib/endorsed 

Catalog. When I do this, I get the above error from Spring MXParser error. The strange thing here is under the windows, it works, but not on Ubuntu. When I run the @andhi test program below with an approved setting, I get OK instead of an error. But for some reason, it looks like Spring under Ubuntu, does not collect the JSR173 jar file that is installed in the approved directory (which is an STAX implementation).

+6
source share
3 answers

Ok, I appreciate all the comments here, but no one was able to solve my problem, so I worked on this as follows. I installed Metro-2.2 on Tomcat 7. Then, since my application is a Spring command-line application, I built a war for it so that it can work in the tomcat container. This included placing all of my libraries for my application in WEB-INF / lib, my configuration files in WEB-INF / classes. In the WEB-INF directory, I put the web.xml file, which looks like this:

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/remote-scheduler-spring-config.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <session-config> <session-timeout>60</session-timeout> </session-config> </web-app> 

index.jsp is empty because this application does not have a component that accesses the web interface. The spring -config parameter is my Spring top-level configuration file, which will be loaded from the command line. My ant build then creates war from this application and it works great. So I'm still not sure why my approved files in jvm do not work using extended: the class flag, as suggested, showed that they are loading, but using tomcat as a container and loading the classes that I need there, Jersey is happy and all the problems disappeared. Thanks again for your help on this issue.

+1
source

It seems to me like a class problem. Have you checked if there are other jaxb-impl-xyzjar or jaxb-api-klmjar in your classpath? JSonConfiguration looking for the class com.sun.xml.bind.annotation.OverrideAnnotationOf , which is part of the JRE7 rt.jar .

You can check your JRE installation using the following simple program:

 import com.sun.jersey.api.json.JSONConfiguration; public class TestNaturalJSon { public static void main(String[] args) { JSONConfiguration config = JSONConfiguration.natural().build(); System.out.println("OK"); } } 

If you are using maven, you can use pom with the following dependencies:

 <dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.12</version> <exclusions> <exclusion> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> </exclusion> <exclusion> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </exclusion> </exclusions> </dependency> </dependencies> 
+3
source

To find out where the class is loaded from, you must run the JVM command line with the -verbose:class option.

Thus, you can guess what is wrong by looking at the last detailed lines just before the javax.xml.stream.FactoryConfigurationError exception is thrown or just before the JAXB RI 2.1.10 not found diagnostic message.

So, you can get the jar where the implementation comes from and check if the endorsed directory is used or not ...

+2
source

Source: https://habr.com/ru/post/912511/


All Articles