用Jersey构建RESTful服务简单示例,遭遇的tomcat和jdk的版本问题

当前环境:

web工程的jdk: jdk1.6.0_43(x64)
tomcat: apache-tomcat-7.0.53(x64)
tomcat使用的jdk: jdk1.6.0_43(x64)

运行tomcat,控制台输出如下:

 1 2016-7-21 9:23:15 org.apache.catalina.core.AprLifecycleListener init
 2 信息: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8.
 3 2016-7-21 9:23:15 org.apache.catalina.core.AprLifecycleListener init
 4 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
 5 2016-7-21 9:23:16 org.apache.catalina.core.AprLifecycleListener initializeSSL
 6 信息: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013)
 7 2016-7-21 9:23:16 org.apache.coyote.AbstractProtocol init
 8 信息: Initializing ProtocolHandler ["http-apr-8080"]
 9 2016-7-21 9:23:16 org.apache.coyote.AbstractProtocol init
10 信息: Initializing ProtocolHandler ["ajp-apr-8009"]
11 2016-7-21 9:23:16 org.apache.catalina.startup.Catalina load
12 信息: Initialization processed in 1113 ms
13 2016-7-21 9:23:16 org.apache.catalina.core.StandardService startInternal
14 信息: Starting service Catalina
15 2016-7-21 9:23:16 org.apache.catalina.core.StandardEngine startInternal
16 信息: Starting Servlet Engine: Apache Tomcat/7.0.53
17 2016-7-21 9:23:16 org.apache.catalina.startup.HostConfig deployDirectory
18 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\docs
19 2016-7-21 9:23:17 org.apache.tomcat.websocket.server.WsSci onStartup
20 信息: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.
21 2016-7-21 9:23:17 org.apache.catalina.startup.HostConfig deployDirectory
22 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\examples
23 2016-7-21 9:23:17 org.apache.catalina.core.ApplicationContext log
24 信息: ContextListener: contextInitialized()
25 2016-7-21 9:23:17 org.apache.catalina.core.ApplicationContext log
26 信息: SessionListener: contextInitialized()
27 2016-7-21 9:23:17 org.apache.catalina.core.ApplicationContext log
28 信息: ContextListener: attributeAdded(‘org.apache.jasper.compiler.TldLocationsCache‘, ‘[email protected]‘)
29 2016-7-21 9:23:17 org.apache.catalina.startup.HostConfig deployDirectory
30 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\host-manager
31 2016-7-21 9:23:17 org.apache.catalina.startup.HostConfig deployDirectory
32 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\manager
33 2016-7-21 9:23:17 org.apache.catalina.startup.HostConfig deployDirectory
34 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\ROOT
35 2016-7-21 9:23:17 org.apache.catalina.startup.HostConfig deployDirectory
36 信息: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\webdemo2
37 2016-7-21 9:23:17 org.apache.catalina.loader.WebappClassLoader validateJarFile
38 信息: validateJarFile(F:\Tomcat7\apache-tomcat-7.0.53\webapps\webdemo2\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
39 2016-7-21 9:23:18 org.apache.catalina.core.ContainerBase addChildInternal
40 严重: ContainerBase.addChild: start:
41 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/webdemo2]]
42     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
43     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
44     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
45     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
46     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229)
47     at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
48     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
49     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
50     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
51     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
52     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
53     at java.lang.Thread.run(Thread.java:662)
54 Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)
55     at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2961)
56     at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
57     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
58     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
59     at java.lang.Class.forName0(Native Method)
60     at java.lang.Class.forName(Class.java:249)
61     at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:187)
62     at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:152)
63     at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1543)
64     at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1265)
65     at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:873)
66     at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:371)
67     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
68     at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
69     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
70     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
71     ... 11 more
72 2016-7-21 9:23:18 org.apache.catalina.startup.HostConfig deployDirectory
73 严重: Error deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\webdemo2
74 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/webdemo2]]
75     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
76     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
77     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
78     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229)
79     at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
80     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
81     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
82     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
83     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
84     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
85     at java.lang.Thread.run(Thread.java:662)

注意19行和20行:
2016-7-21 9:23:17 org.apache.tomcat.websocket.server.WsSci onStartup
信息: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.

这里是说,jersey在jdk1.6下是不支持的,至少要jdk1.7。

将tomcat使用的jdk更改为:jdk1.7.0_17(x86),重启tomcat会出现如下信息

 1 java.lang.UnsatisfiedLinkError: F:\Tomcat7\apache-tomcat-7.0.53\bin\tcnative-1.dll: Can‘t load AMD 64-bit .dll on a IA 32-bit platform
 2     at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 3     at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
 4     at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
 5     at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
 6     at java.lang.Runtime.loadLibrary0(Runtime.java:845)
 7     at java.lang.System.loadLibrary(System.java:1084)
 8     at org.apache.tomcat.jni.Library.<init>(Library.java:40)
 9     at org.apache.tomcat.jni.Library.initialize(Library.java:172)
10     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11
12     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
13     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
14     at java.lang.reflect.Method.invoke(Method.java:601)
15     at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:178)
16     at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:83)
17
18     at org.apache.catalina.connector.Connector.setProtocol(Connector.java:592)
19     at org.apache.catalina.connector.Connector.<init>(Connector.java:66)
20     at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62)
21     at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1288)
22     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
23     at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
24     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1303)
25     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
26     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
27     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
28     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
29     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
30     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
31
32     at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
33     at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
34     at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
35     at org.apache.catalina.startup.Catalina.load(Catalina.java:615)
36     at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
37     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
38     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
39     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
40     at java.lang.reflect.Method.invoke(Method.java:601)
41     at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
42     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
43 七月 21, 2016 9:39:40 上午 org.apache.catalina.core.AprLifecycleListener init
44 INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: F:\jdk1.7.0_17\jdk1.7.0_17\bin;F:\Tomcat7\apache-tomcat-7.0.53\bin
45 七月 21, 2016 9:39:40 上午 org.apache.coyote.AbstractProtocol init
46 INFO: Initializing ProtocolHandler ["http-bio-8080"]
47 七月 21, 2016 9:39:40 上午 org.apache.coyote.AbstractProtocol init
48 INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
49 七月 21, 2016 9:39:40 上午 org.apache.catalina.startup.Catalina load
50 INFO: Initialization processed in 430 ms
51 七月 21, 2016 9:39:40 上午 org.apache.catalina.core.StandardService startInternal
52 INFO: Starting service Catalina
53 七月 21, 2016 9:39:40 上午 org.apache.catalina.core.StandardEngine startInternal
54 INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
55 七月 21, 2016 9:39:40 上午 org.apache.catalina.startup.HostConfig deployDirectory
56 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\docs
57 七月 21, 2016 9:39:41 上午 org.apache.catalina.startup.HostConfig deployDirectory
58 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\examples
59 七月 21, 2016 9:39:41 上午 org.apache.catalina.core.ApplicationContext log
60 INFO: ContextListener: contextInitialized()
61 七月 21, 2016 9:39:41 上午 org.apache.catalina.core.ApplicationContext log
62 INFO: SessionListener: contextInitialized()
63 七月 21, 2016 9:39:41 上午 org.apache.catalina.core.ApplicationContext log
64 INFO: ContextListener: attributeAdded(‘org.apache.jasper.compiler.TldLocationsCache‘, ‘[email protected]‘)
65 七月 21, 2016 9:39:41 上午 org.apache.catalina.startup.HostConfig deployDirectory
66 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\host-manager
67 七月 21, 2016 9:39:41 上午 org.apache.catalina.startup.HostConfig deployDirectory
68 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\manager
69 七月 21, 2016 9:39:41 上午 org.apache.catalina.startup.HostConfig deployDirectory
70 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\ROOT
71 七月 21, 2016 9:39:41 上午 org.apache.catalina.startup.HostConfig deployDirectory
72 INFO: Deploying web application directory F:\Tomcat7\apache-tomcat-7.0.53\webapps\webdemo2
73 七月 21, 2016 9:39:41 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
74 INFO: validateJarFile(F:\Tomcat7\apache-tomcat-7.0.53\webapps\webdemo2\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
75 七月 21, 2016 9:39:43 上午 com.sun.faces.config.ConfigureListener contextInitialized
76 INFO: 初始化上下文 ‘/webdemo2‘ 的 Mojarra 2.0.3 (FCS b03)
77 七月 21, 2016 9:39:43 上午 com.sun.faces.spi.InjectionProviderFactory createInstance
78 INFO: JSF1048: PostConstruct/PreDestroy 注释。标这些注释的 ManagedBeans 方法将表示注释已处理。
79 七月 21, 2016 9:39:45 上午 org.apache.coyote.AbstractProtocol start
80 INFO: Starting ProtocolHandler ["http-bio-8080"]
81 七月 21, 2016 9:39:45 上午 org.apache.coyote.AbstractProtocol start
82 INFO: Starting ProtocolHandler ["ajp-bio-8009"]
83 七月 21, 2016 9:39:45 上午 org.apache.catalina.startup.Catalina start
84 INFO: Server startup in 4306 ms

对于这次的error,网上有很多的解释,这里的解决办法:
给出的异常信息是:无法用32位去加载64位的.dll文件。所以,将tomcat的jdk改为jdk1.8.0_40(x64),重启tomcat,正常执行。

结论:使用tomcat部署Jersey的项目,tomcat内置的jdk应为1.7以上,并且tomcat内置的jdk和tomcat的操作位数一致。

时间: 2024-10-10 01:26:39

用Jersey构建RESTful服务简单示例,遭遇的tomcat和jdk的版本问题的相关文章

用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2

一.整体说明 本例执行演示了用 Jersey 构建 RESTful 服务中.怎样集成 Spring3 二.环境 1.上文的项目RestDemo 2.Spring及其它相关的jar ,导入项目 三.配置 1.根文件夹下下创建 Spring 的配置文件applicationContext.xml: 配置例如以下: 四.执行 1.先执行项目 2.执行UserClient.java測试,控制台输出例如以下 ****添加用户addUser**** ****查询全部getAllUsers**** [{"us

无废话Jersey构建RESTful服务之WebService系统教程 --3 [JAVA对象转成JSON输出]

一. 总体说明 XML和JSON 是最为常用的数据交换格式.本例子演示如何将JAVA对象,转换成JSON输出. 二.流程 1.在上文项目中, 在“cn.itrush.rest.resources.UserResource“中增加代码,代码如下: 1 package cn.itrush.rest.resources; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 impo

用Jersey构建RESTful服务1--HelloWorld

本文具体代码实现参考自:http://blog.csdn.net/kkkloveyou/article/details/21391033,如有问题,请联系我. 本文仅仅是对原文做了一点补充,感谢原作者的精彩文章,对我帮助很大. 一,环境 IDE:myeclipse10 tomcat版本,jdk版本会在下一篇文章做详细说明. 二,项目的构建 在https://jersey.java.net/download.html中,可以发现两条很实用的mvn指令: 命令一:构建基于 Servlet conta

jersey+maven构建restful服务

一.新建一个Maven Web项目 a) 新建一个简单的Maven项目 b) 将简单的Maven项目转成Web项目 (若没出现further configuration available--或里面的内容不是context相关设置,将Dynamic Web Module版本调高一些试试就自动出现了) 二.修改pom文件,添加jersey依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="htt

【用jersey构建REST服务】系列文章

1.用Jersey构建RESTful服务1--HelloWorld http://blog.csdn.NET/kkkloveyou/article/details/21391033 2.用Jersey构建RESTful服务2--JAVA对象转成XML输出 http://blog.csdn.Net/kkkloveyou/article/details/21415735 3.用Jersey构建RESTful服务3--JAVA对象转成JSON输出 http://blog.csdn.net/kkklov

使用ASP.Net WebAPI构建REST-ful 服务(一)——简单的示例

由于给予REST的Web服务非常简单易用,它越来越成为企业后端服务集成的首选方法.本文这里介绍一下如何通过微软的Asp.Net WebAPI快速构建REST-ful 服务. 首先创建一个Asp.Net Web应用程序(我这里用的是Visual Studio 2013,它已经内置了Web API2). 在出来的模板中选择Empty(空项目),并勾选WebAPI.点击确定后,就创建了一个空的WebAPI服务. 此时只有一个空项目,还没有任何功能,在进行下一步之前,首先我们来看一下REST的基本操作模

Maven + Jetty + Jersey搭建RESTful服务

IntelliJ IDEA + Maven + Jetty + Jersey搭建RESTful服务 本文参考以下内容: 使用Jersey实现RESTful风格的webservice(一) Starting out with Jersey & Apache Tomcat using IntelliJ --------------------------------------------------正文------------------------------------------------

Springboot &amp; Mybatis 构建restful 服务四

Springboot & Mybatis 构建restful 服务四 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务三 2 restful service 添加 Apache POI生成 Excel 文件 1)修改 POM.xml文件 添加 Apache POI 的依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-oo

Springboot &amp; Mybatis 构建restful 服务三

Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful service 添加日志 1)新建 logback.xml文件(配置生成的日志文件的格式) src/main/resources/logback.xml <?xml version="1.0" encoding="UTF-8"?>   <!-- 设置根