我正在使用 Oracle Java 7 Update 3 在 Ubuntu 上运行测试。根据发行说明,它包含 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.
机器说它上面有 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)
但是,当我运行使用 JAX-RS 并使用 JAXB 编码某些对象的应用程序时,出现以下错误:
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!
在服务器端,我最初遇到了同样的错误,所以我将 metro-2.2-standalone 安装到 tomcat 中,这解决了这个问题。 (即使它在 java 7 中运行)。
在 Windows 客户端上,我被迫将 JAXB-2.2.5 api、impl 和 jsr173 jar 添加到我认可的 java 目录中以使其正常工作(还有 Java 7 update 3)。
当我尝试在 ubuntu 下执行 jaxb 技巧时,我将文件放在/usr/lib/jvm/java-7-oracle/jre/lib/endorsed 下,我得到了一个不同的错误:
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
我在类中初始化 JAX-RS/JAXB 代码如下:
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());
我尝试用 source=1.7 和 target=1.7 编译它,因为它仍然设置为 1.6,我在想也许它假设 1.6 早期版本的旧版本太旧了,但这并没有解决也有问题。
我运行了@andih 的测试程序,但仍然出现错误。我开始认为这是一个 VM 问题:
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)
回顾一下我安装文件的 JAXB-2.2.5 RI 认可的解决方案:
jaxb-api.jar
jaxb-impl.jar
jsr173_1.0_api.jar
进入:
/usr/lib/jvm/java-7-oracle/jre/lib/endorsed
目录。当我这样做时,我从 Spring MXParser 错误中得到了上述错误。奇怪的是在 windows 下这行得通,但在 Ubuntu 上行不通。当我使用认可的设置运行下面@andhi 的测试程序时,我得到了 OK 而不是错误。但出于某种原因,Ubuntu 下的 Spring 似乎没有获取安装在认可目录(这是 STAX 实现)中的 JSR173 jar 文件。
最佳答案
在我看来像是类路径问题。您是否检查过您的类路径中是否还有其他 jaxb-impl-x.y.z.jar 或 jaxb-api-k.l.m.jar? JSonConfiguration 查找类 com.sun.xml.bind.annotation.OverrideAnnotationOf,它是 JRE7 rt.jar 的一部分。
您可以使用以下简单程序检查您的 JRE 安装:
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");
}
}
如果您使用 maven,则可以使用具有以下依赖项的 pom:
<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>
关于java - Java 7 下的 JAXB 问题它说找不到 RI 2.1.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032032/
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候
遍历文件夹我们通常是使用递归进行操作,这种方式比较简单,也比较容易理解。本文为大家介绍另一种不使用递归的方式,由于没有使用递归,只用到了循环和集合,所以效率更高一些!一、使用递归遍历文件夹整体思路1、使用File封装初始目录,2、打印这个目录3、获取这个目录下所有的子文件和子目录的数组。4、遍历这个数组,取出每个File对象4-1、如果File是否是一个文件,打印4-2、否则就是一个目录,递归调用代码实现publicclassSearchFile{publicstaticvoidmain(String[]args){//初始目录Filedir=newFile("d:/Dev");Datebeg
我基本上来自Java背景并且努力理解Ruby中的模运算。(5%3)(-5%3)(5%-3)(-5%-3)Java中的上述操作产生,2个-22个-2但在Ruby中,相同的表达式会产生21个-1-2.Ruby在逻辑上有多擅长这个?模块操作在Ruby中是如何实现的?如果将同一个操作定义为一个web服务,两个服务如何匹配逻辑。 最佳答案 在Java中,模运算的结果与被除数的符号相同。在Ruby中,它与除数的符号相同。remainder()在Ruby中与被除数的符号相同。您可能还想引用modulooperation.
Java的Collections.unmodifiableList和Collections.unmodifiableMap在Ruby标准API中是否有等价物? 最佳答案 使用freeze应用程序接口(interface):Preventsfurthermodificationstoobj.ARuntimeErrorwillberaisedifmodificationisattempted.Thereisnowaytounfreezeafrozenobject.SeealsoObject#frozen?.Thismethodretur
在Java中,可以像这样从一个字符串创建一个IO流:Readerr=newStringReader("mytext");我希望能够在Ruby中做同样的事情,这样我就可以获取一个字符串并将其视为一个IO流。 最佳答案 r=StringIO.new("mytext")和here'sthedocumentation. 关于java-Java的StringReader的Ruby等价物是什么?,我们在StackOverflow上找到一个类似的问题: https://st