使用gradle启动tomcat时出现ClassNotFoundException

时间:2015-12-22 16:25:03

标签: java tomcat gradle

我正在尝试使用' com.bmuschko启动我的webapp:gradle-tomcat-plugin:2.2.4'

当我构建.war并将其放入我的tomcats / webapp目录时,它可以工作。

   gradle tomcatRun

但是给了我以下例外:

:myApp:tomcatRun
Executing task ':myApp:tomcatRun' (up-to-date check took 0.001 secs) due to:
  Task.upToDateWhen is false.
Configuring Tomcat for project ':myApp'
HTTP protocol handler classname = org.apache.coyote.http11.Http11Protocol
HTTPS protocol handler classname = org.apache.coyote.http11.Http11Protocol
Webapp source directory = C:\projects\myApp\src\main\webapp
Resolved Tomcat 7x server implementation in classpath
Additional runtime resources classpath = []
Web app loader classpath = [C:\projects\myApp\build\classes\main, C:\projects\myApp\build\resources\main, 
home\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.7\2b8019b6249bb05d81d3a3094e468753e2b21311\slf4j-api-1.7.7.jar,
home\.gradle\caches\modules-2\files-2.1\log4j\log4j\1.2.17\5af35056b4d257e4b64b9e8069c0746e8b08629f\log4j-1.2.17.jar, 
home\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-log4j12\1.7.7\58f588119ffd1702c77ccab6acb54bfb41bed8bd\slf4j-log4j12-1.7.7.jar, 
.... Skipping more libs ....

]
Initializing ProtocolHandler ["http-bio-8080"]
Initializing ProtocolHandler ["ajp-bio-8009"]
Starting service Tomcat
Starting Servlet Engine: Apache Tomcat/7.0.47
No global web.xml found
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/slf4j/spi/LoggerFactoryBinder
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1617)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288)
        at org.apache.wicket.protocol.http.WicketFilter.<clinit>(WicketFilter.java:64)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at java.lang.Class.newInstance(Class.java:442)
        at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:143)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
        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: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: java.lang.ClassNotFoundException: org.slf4j.spi.LoggerFactoryBinder
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 37 more

如您所见,slf4j-log4j和slf4j-api都在webapp-classpath中。

我的build.gradle片段

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.4'
    }
}


apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'com.bmuschko.tomcat'


 ....



dependencies {
.....


compile 'org.slf4j:slf4j-api:1.7.7'


runtime 'javax.servlet:jstl:1.1.2'
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
providedCompile 'org.apache.tomcat:tomcat-catalina:7.0.47'  

def tomcatVersion = '7.0.47'
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}"    


 }

希望有人能帮助我解决这个问题。

0 个答案:

没有答案