2014-01-24 61 views
7

我創建了一個web應用程序,我需要它能夠與圖形數據庫(我正在使用Titan)進行交互。當添加泰坦的依賴,我收到以下錯誤,當我嘗試在Tomcat中部署該WAR:使Tomcat忽略WEB-INF/LIB中的Servlet

SEVERE: A child container failed during start 
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] 
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) 
    at java.util.concurrent.FutureTask.get(FutureTask.java:188) 
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) 
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
    ... 6 more 
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/catalina/loader/WebappClassLoader) previously initiated loading for a different type with name "javax/servlet/ServletContext" 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1191) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1669) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) 
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:173) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 6 more 

Jan 24, 2014 11:43:04 AM 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[Tomcat].StandardHost[localhost]] 
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) 
    at java.util.concurrent.FutureTask.get(FutureTask.java:188) 
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) 
    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.Tomcat.start(Tomcat.java:341) 
    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1238) 
    at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:592) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: org.apache.catalina.LifecycleException: A child container failed during start 
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131) 
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 6 more 

一些進一步的研究使我發現,土衛六是包括不是一個,而是兩個servlet的API-2.5。 jar文件。我知道當servlet jar被放置在WEB-INF/lib中時,Tomcat不會感激它,並且假設這是問題的根源。有兩種可能的解決辦法是:

  • 讓泰坦使用servlet罐子內的Tomcat

  • 告訴Tomcat能夠忽略WEB-INF/lib中的servlet罐子。

但是,我不知道如何去做這些事情。任何人都可以將我指向正確的方向嗎?

另外,按照第一潛在的解決方案,我試圖添加以下到我的Maven的pom.xml:

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.5</version> 
    <scope>provided</scope> 
</dependency> 

但是,泰坦還包括了它的Java Servlet的的自己的版本。

+1

什麼是泰坦的servlet? – MariuszS

+1

Titan是一個圖形數據庫前端,它位於cassandra或hbase之上進行存儲。以下是網站:http://thinkaurelius.github.io/titan/ – cscan

+0

由於Titan文件存在問題,因爲API必須使用'provided'代碼。你所做的每件事都只是一種解決方法。 –

回答

20

申報servlet作爲provided

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.5</version> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.5-20081211</version> 
    <scope>provided</scope> 
</dependency> 

和排除泰坦

<dependency> 
    <groupId>titan</groupId> 
    <artifactId>titan</artifactId> 
    <exclusions> 
     <exclusion> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 
+1

人們也需要申報二級servlet作爲提供:\t \t org.mortbay.jetty \t servlet的API \t 2.5-20081211 \t 提供 cscan

+0

OK,回答更新時間: ) – MariuszS

+1

如果它不起作用,則將排除替換爲排除。 – Ghost