启动时缺少类,但之后可用

时间:2016-04-21 02:03:09

标签: spring tomcat gradle classpath

我正在将a project从旧的Ant脚本迁移到Gradle。对于开发,我使用gradle-tomcat-plugin以及javawar插件。

该项目是在Docker容器中构建的,这对我来说很好,但不适合我的同事。当他运行gradle tomcatRun时,他会收到如下错误:

A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/rsa]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/rsa]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: ServletException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)
    at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:287)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:415)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:892)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5412)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: ServletException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    ... 20 more
A child container failed during start

我认为这是指javax.servlet.ServletException。但是,如果我强制其中一个servlet抛出一个ServletException(我可以测试它,因为它在我的机器上正常加载),它可以找到没有问题的类。

我的构建文件看起来像这样(full source here):

providedCompile (
    "org.apache.tomcat:tomcat-catalina:$tomcatVersion",
)

compile (
    'com.googlecode.lambdaj:lambdaj:2.3.3',
    'com.sun.xml.bind:jaxb-impl:2.1',
    'commons-io:commons-io:1.3.2',
    'commons-net:commons-net:3.4',
    'javax.validation:validation-api:1.0.0.GA',
    'org.codehaus.jackson:jackson-mapper-asl:1.7.1',
    'org.hibernate:hibernate-validator:4.2.0.Final',
    "org.springframework:org.springframework.web:$springVersion",
    "org.springframework:org.springframework.web.servlet:$springVersion",
    'rome:rome:1.0',
)

runtime (
    'commons-fileupload:commons-fileupload:1.2',
    "org.springframework:spring-oxm:$springVersion",
)

tomcat (
    "org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
    "org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion",
    "org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion",
)

我还缺少另一个ServletException .jar吗?或者是.jar可能在服务器启动期间没有加载,但后来加载?该应用程序目前configured使用servlet API 2.4。我已经看到其他一些线程说要升级它,但将其改为2.5并没有帮助。

1 个答案:

答案 0 :(得分:0)

好的,这很令人尴尬:我的同事的源代码树中肯定有一些陈旧的文件,可能被.gitignore掩盖了。对存储库进行干净的检查已经修复了#34;问题。

我说"修复"因为我们从来没有真正了解它:错误是它无法找到ServletException。我在默认包中实现了自己的ServletException(感谢Thilo的提示),但它只显示了另一个类似的错误。无论如何它现在都有效,所以很可能只是一个类路径问题涉及一个不应该在源树中的文件。