当前环境:
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的操作位数一致。