web-dev-qa-db-ja.com

java.lang.ClassNotFoundException:javax.servlet.ServletContainerInitializer

私はいくつかのサーブレットの作成に取り組んでおり、それらはすべて正常に動作し、Tomcatはこれまで何も問題なく実行されました。次に、JERSEYを使用するクラスファイルを作成しましたが、実行しようとしたときにTomcatが起動しませんでした。 EclipseにWeb開発ツールプラグインがインストールされています。コンパイルを実行するたびに、

Java.lang.ClassNotFoundException:javax.servlet.ServletContainerInitializer

これはコンソールからの出力です

May 08, 2012 4:51:36 PM org.Apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the Java.library.path: C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\bin\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Python27\Scripts;C:\Program Files (x86)\SSH Communications Security\SSH Tectia\SSH Tectia AUX;C:\Program Files (x86)\SSH Communications Security\SSH Tectia\SSH Tectia AUX\Support binaries;C:\Program Files (x86)\SSH Communications Security\SSH Tectia\SSH Tectia Broker;C:\Program Files (x86)\SSH Communications Security\SSH Tectia\SSH Tectia Client;C:\Program Files\CREDANT\Shield v7.1\;C:\Development Tools\Java\Eclipse;;.
May 08, 2012 4:51:36 PM org.Apache.Tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.Eclipse.jst.jee.server:Test_Server' did not find a matching property.
May 08, 2012 4:51:37 PM org.Apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-80"]
May 08, 2012 4:51:37 PM org.Apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 08, 2012 4:51:37 PM org.Apache.catalina.startup.Catalina load
INFO: Initialization processed in 546 ms
May 08, 2012 4:51:37 PM org.Apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 08, 2012 4:51:37 PM org.Apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.27
May 08, 2012 4:51:37 PM org.Apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
Java.util.concurrent.ExecutionException: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Test_Server]]
    at Java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at Java.util.concurrent.FutureTask.get(Unknown Source)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1128)
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:782)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1566)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1556)
    at Java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at Java.util.concurrent.FutureTask.run(Unknown Source)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at Java.lang.Thread.run(Unknown Source)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Test_Server]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    ... 7 more
Caused by: Java.lang.NoClassDefFoundError: javax/servlet/ServletContainerInitializer
    at Java.lang.ClassLoader.defineClass1(Native Method)
    at Java.lang.ClassLoader.defineClass(Unknown Source)
    at Java.security.SecureClassLoader.defineClass(Unknown Source)
    at Java.net.URLClassLoader.defineClass(Unknown Source)
    at Java.net.URLClassLoader.access$100(Unknown Source)
    at Java.net.URLClassLoader$1.run(Unknown Source)
    at Java.net.URLClassLoader$1.run(Unknown Source)
    at Java.security.AccessController.doPrivileged(Native Method)
    at Java.net.URLClassLoader.findClass(Unknown Source)
    at Java.lang.ClassLoader.loadClass(Unknown Source)
    at Java.lang.ClassLoader.loadClass(Unknown Source)
    at Sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at Java.lang.ClassLoader.loadClass(Unknown Source)
    at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1626)
    at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1556)
    at Java.lang.Class.forName0(Native Method)
    at Java.lang.Class.forName(Unknown Source)
    at org.Apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.Java:1601)
    at org.Apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.Java:1519)
    at org.Apache.catalina.startup.ContextConfig.webConfig(ContextConfig.Java:1222)
    at org.Apache.catalina.startup.ContextConfig.configureStart(ContextConfig.Java:855)
    at org.Apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.Java:345)
    at org.Apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.Java:119)
    at org.Apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.Java:90)
    at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5161)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 7 more
Caused by: Java.lang.ClassNotFoundException: javax.servlet.ServletContainerInitializer
    at Java.net.URLClassLoader$1.run(Unknown Source)
    at Java.net.URLClassLoader$1.run(Unknown Source)
    at Java.security.AccessController.doPrivileged(Native Method)
    at Java.net.URLClassLoader.findClass(Unknown Source)
    at Java.lang.ClassLoader.loadClass(Unknown Source)
    at Java.lang.ClassLoader.loadClass(Unknown Source)
    ... 33 more

May 08, 2012 4:51:37 PM org.Apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
Java.util.concurrent.ExecutionException: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at Java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at Java.util.concurrent.FutureTask.get(Unknown Source)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1128)
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:302)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:443)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:732)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:675)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at Java.lang.reflect.Method.invoke(Unknown Source)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:322)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:450)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1566)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1556)
    at Java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at Java.util.concurrent.FutureTask.run(Unknown Source)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at Java.lang.Thread.run(Unknown Source)
Caused by: org.Apache.catalina.LifecycleException: A child container failed during start
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1136)
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:782)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 7 more

May 08, 2012 4:51:37 PM org.Apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.Apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:675)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at Java.lang.reflect.Method.invoke(Unknown Source)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:322)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:450)
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:732)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 7 more
Caused by: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:154)
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:443)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 9 more
Caused by: org.Apache.catalina.LifecycleException: A child container failed during start
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1136)
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:302)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    ... 11 more

May 08, 2012 4:51:37 PM org.Apache.catalina.startup.Catalina start
INFO: Server startup in 416 ms

これはどのように引き起こされ、どのように解決できますか?

10
cyberbemon

javax/servlet/ServletContainerInitializerServlet 3.0のクラスであり、Tomcat 6ではサポートされていません。

おそらくservlet.jarがCLASSPATHのどこかに浮かんでいるはずですが、浮いてはいけません。 Tomcatのクラスローダーは期待どおりに正常に動作しないため、これは実際にクラスローダーを混乱させます(上記のリンクを参照)。 servlet.jarは、$CATALINA_HOME/libで1回だけ検出されます。

10
Hardik Mishra

EclipseでTomcatサーバーを実行している場合、ローカルのTomcat作業ディレクトリーが妨害される可能性があるため、明示的にクリアする必要があります。これは、プロジェクトでクリーンビルドを実行するのと同じではないことに注意してください。[サーバー]ウィンドウから:起動しようとしているサーバーを右クリックします。

5
The Camster

tomcatサーバーを右クリックして、Tomcat作業ディレクトリをクリーンアップしてから、Tomcatをクリーンアップします。それが動作します。

0
Himanshu

遅い答えですが、これは誰かを助けるかもしれません。

これは、ジャージーが新しいバージョンのJava=を使用して作成され、古いバージョンのJavaで実行しようとしているために発生したと考えています。Javaを更新してください。 =バージョンまたはJavaバージョンをサポートする古いバージョンのJerseyをダウンロードします。

Window -> Preferences -> Java -> Compiler -> set "Compiler compliance level" to 1.7. 

ジャージーのドキュメントから:

Until version 2.6, Jersey was compiled with Java SE 6. This has changes in Jersey 2.7. 
Now almost all Jersey components are compiled with Java SE 7 target. It means, that 
you will need at least Java SE 7 to be able to compile and run your application 
that is using latest Jersey. Only core-common and core-client modules are still 
compiled with Java class version runnable with Java SE 6. 
0
Susie

今日も同じ問題が発生しました。最終的に、ユーザーライブラリが空になったことが判明しました。ただし、表示されたエラーメッセージはそれについてのヒントを提供しませんでした。

0
user2942470