tomcatRun与com.bmuschko.tomcat-base在gradle中显示404或空页

时间:2015-01-23 14:34:31

标签: java tomcat gradle

我在NetBeans IDE 8.0.2中使用gradle和com.bmuschko.tomcat 2.0插件在本地tomcat 6容器中调用我的Web应用程序。如果我运行“tomatRunWar”一切正常,在浏览器中我可以看到我的工作Web应用程序。但是,如果我尝试“tomcatRun”,则会出现404错误,指出无法找到路径“/”。

这是我的build.gradle:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath "com.bmuschko:gradle-tomcat-plugin:2.0"
  }
}

plugins {
  id "com.bmuschko.tomcat" version "2.0"
}

apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'com.bmuschko.tomcat-base'
apply plugin: 'war'

sourceCompatibility = 1.7
targetCompatibility = 1.7

if (!hasProperty('mainClass')) {
    ext.mainClass = ''
}

sourceSets {
    main {
        java {
            srcDir '/src/main/java'
        }
        resources {
            srcDir '/src/main/java'
            include '**/*.xml'
        }
    }
}

war {
    archiveName = 'Frontend.war'
    exclude('**/*.java,**/*.form')
}


[tomcatRun, tomcatRunWar]*.contextPath = '/frontend'
[tomcatRun, tomcatRunWar]*.reloadable = true
[tomcatRun, tomcatRunWar]*.configFile = file('src/main/webapp/META-INF/context.xml')
[tomcatRun, tomcatRunWar]*.httpPort = 8080
[tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8081
[tomcatRun, tomcatStop]*.stopKey = 'stopKey'

task run << {
    //println "Stopping tomcat container"
    //tomcatStop.execute()

    println "Start tomcat container"

    //tomcatRunWar.execute()
    tomcatRun.execute()
}

dependencies {
    providedCompile 'javax.servlet:servlet-api:2.5',
                    'javax.servlet:jsp-api:2.0'

    def tomcatVersion = '6.0.35'
    tomcat "org.apache.tomcat:catalina:${tomcatVersion}",
           "org.apache.tomcat:coyote:${tomcatVersion}",
           "org.apache.tomcat:jasper:${tomcatVersion}"
}

我的build.gradle出了什么问题? “tomcatRunWar”和“tomcatRun”的启动有什么区别? 来自“tomcatRun”的启动日志显示此信息(“tomcatRunWar”不显示错误消息):

The Server is running at http://localhost:8080/frontend
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/testuser/.gradle/wrapper/dists/gradle-2.1-bin/2pk0g2l49n2sbne636fhtlet6a/gradle-2.1/lib/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/testuser/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.2/7539c264413b9b1ff9841cd00058c974b7cd1ec9/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

这是我的context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/frontend"/>

0 个答案:

没有答案