Gradle(tomcat插件):tomcatRun无法执行GWT JS

Gradle(tomcat插件):tomcatRun无法执行GWT JS,gwt,web-applications,deployment,gradle,tomcat7,Gwt,Web Applications,Deployment,Gradle,Tomcat7,我正在尝试用Gradle(在Ubuntu Linux上)构建一个支持GWT的web应用程序 我已经配置了一切,Gradle成功地构建了应用程序,但是当我运行任务“tomcatRun”时,我只能看到一个空白页面,这是GWT javascript未执行的结果(如果我查看页面源代码,它就在那里)。没有错误,没有来自Tomcat的警告,只有那个空白页 然而,当我运行“tomcatRunWar”时,一切工作都很完美。我不知道什么地方出了问题,为什么会这样 这是我的gradle.build文件: apply

我正在尝试用Gradle(在Ubuntu Linux上)构建一个支持GWT的web应用程序

我已经配置了一切,Gradle成功地构建了应用程序,但是当我运行任务“tomcatRun”时,我只能看到一个空白页面,这是GWT javascript未执行的结果(如果我查看页面源代码,它就在那里)。没有错误,没有来自Tomcat的警告,只有那个空白页

然而,当我运行“tomcatRunWar”时,一切工作都很完美。我不知道什么地方出了问题,为什么会这样

这是我的
gradle.build
文件:

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'tomcat'
apply plugin: 'eclipse-wtp'

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath "org.gradle.api.plugins:gradle-tomcat-plugin:1.0"
  }
}

repositories {
  mavenCentral()
}

dependencies {
  /* Tomcat plugin dependencies */
  def tomcatVersion = '7.0.47'
  tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
         "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
  tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
    exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
  }

  /* Google Web Toolkit */
  def gwtVersion = '2.5.1'
  providedCompile "com.google.gwt:gwt-user:${gwtVersion}"
  providedCompile "com.google.gwt:gwt-dev:${gwtVersion}"
  runtime "com.google.gwt:gwt-servlet:${gwtVersion}"

  /* Spring Security */
  def springVersion = '3.1.4.RELEASE'
  compile "org.springframework.security:spring-security-web:${springVersion}"
  compile "org.springframework.security:spring-security-config:${springVersion}"
}

/* Task to compile the client package GWT code to JavaScript */
task gwtCompile (dependsOn: classes, type: JavaExec) {
  buildDir = "${project.buildDir}/gwt"
  extraDir = "${project.buildDir}/extra"

  inputs.source sourceSets.main.java.srcDirs
  inputs.dir sourceSets.main.output.resourcesDir
  outputs.dir buildDir

  doFirst {
    file(buildDir).mkdirs()
  }

  main = "com.google.gwt.dev.Compiler"

  classpath {
    [
      sourceSets.main.java.srcDirs,         // Java source
      sourceSets.main.output.resourcesDir,  // Generated resources
      sourceSets.main.output.classesDir,    // Generated classes
      sourceSets.main.compileClasspath,     // Dependencies
    ]
  }

  args = [
    '<package_path_to_GWT_module>',        // Our GWT module
    '-war', buildDir,
    '-logLevel', 'INFO',
    '-localWorkers', '2',
    '-compileReport',
    '-extra', extraDir,
  ]

  maxHeapSize = '256M'

}

/* Make the war plugin depend on the gwtCompile task */
war.dependsOn gwtCompile
/* Include the contents of the GWT compilation in the generated WAR file */
war {
  from gwtCompile.buildDir
}

/* Configure the eclipse plugin in case it is used */
eclipse {
  project {
    natures 'com.google.gwt.eclipse.core.gwtNature'
    buildCommand 'com.google.gdt.eclipse.core.webAppProjectValidator'
    buildCommand 'com.google.gwt.eclipse.core.gwtProjectValidator'
  }

  classpath {
    containers 'com.google.gwt.eclipse.core.GWT_CONTAINER'
  }
}
apply插件:“java”
应用插件:“战争”
应用插件:“tomcat”
应用插件:“EclipseWTP”
构建脚本{
存储库{
jcenter()
}
依赖关系{
classpath“org.gradle.api.plugins:gradle-tomcat-plugin:1.0”
}
}
存储库{
mavenCentral()
}
依赖关系{
/*Tomcat插件依赖项*/
def tomcatVersion='7.0.47'
tomcat“org.apache.tomcat.embed:tomcat嵌入核心:${tomcatVersion}”,
“org.apache.tomcat.embed:tomcat嵌入日志juli:${tomcatVersion}”
tomcat(“org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}”){
排除组:“org.eclipse.jdt.core.compiler”,模块:“ecj”
}
/*谷歌网络工具包*/
def gwtVersion='2.5.1'
提供编译“com.google.gwt:gwt用户:${gwtVersion}”
提供编译“com.google.gwt:gwt dev:${gwtVersion}”
运行时“com.google.gwt:gwtservlet:${gwtVersion}”
/*春季安全*/
def springVersion='3.1.4.RELEASE'
编译“org.springframework.security:springsecurityweb:${springVersion}”
编译“org.springframework.security:spring安全配置:${springVersion}”
}
/*将客户端包GWT代码编译为JavaScript的任务*/
任务gwtCompile(dependsOn:classes,type:JavaExec){
buildDir=“${project.buildDir}/gwt”
extraDir=“${project.buildDir}/extra”
inputs.source sourceset.main.java.srcDirs
inputs.dir sourceset.main.output.resourcesDir
outputs.dir buildDir
首先{
文件(buildDir).mkdirs()
}
main=“com.google.gwt.dev.Compiler”
类路径{
[
sourceSets.main.java.srcDirs,//java源代码
sourceset.main.output.resourcesDir,//生成的资源
sourceset.main.output.classesDir,//生成的类
sourceset.main.compileClasspath,//依赖项
]
}
args=[
'',//我们的GWT模块
“战争”,buildDir,
“-logLevel”、“INFO”,
“-localWorkers”,“2”,
“-compileReport”,
“-额外”,extraDir,
]
maxHeapSize='256M'
}
/*使war插件依赖于gwtCompile任务*/
war.dependsOn gwtCompile
/*在生成的WAR文件中包含GWT编译的内容*/
战争{
来自gwtCompile.buildDir
}
/*配置eclipse插件以备使用*/
蚀{
计划{
natures'com.google.gwt.eclipse.core.gwtNature'
buildCommand'com.google.gdt.eclipse.core.webAppProjectValidator'
buildCommand'com.google.gwt.eclipse.core.gwtProjectValidator'
}
类路径{
容器'com.google.gwt.eclipse.core.gwt_CONTAINER'
}
}
我的目录树如下所示:

ProjectHome
-- src
   -- main
     -- java
        -- <packages>
     -- webapp
        -- WEB-INF
           -- web.xml
        -- index.html
   -- test
-- build.gradle
ProjectHome
--src
--主要
--爪哇
-- 
--网络应用
--WEB-INF
--web.xml
--index.html
--试验
--格雷德尔先生
我还将生成的WAR目录树与“tomcatRun”任务(build/libs/ProjectName)使用的目录树进行了比较,它们看起来完全相同

有人对此有什么想法吗


//编辑:实际上,它不会显示空页面,它只是无法执行GWT Javascript,将内容分配给正文中的唯一div。

好的,找到了解决方案

实际上,您必须将所需的文件复制到src/main/webapp目录中(或者让构建脚本这样做,或者更好地配置tomcat插件以从别处读取文件——如果可能的话),因为tomcatRun从那里读取文件。我希望它从WAR文件所在的位置(build/libs)读取它们,但事实并非如此


因此,考虑到GWT插件仍在开发中,这里最好的选择是使用tomcatRunWar选项。

任务
tomcatRun
不会事先绑定WAR文件。它使用Java和War插件提供的源目录约定来解析文件!谢谢,有没有办法修改构建脚本来告诉tomcat插件使用构建文件的位置呢?你的确切意思是什么?我的gradle脚本将文件构建到Project/build目录。有没有办法让tomcatRun使用该文件夹作为根webapp目录?我想我还是不能理解你的意思。你说的是GWT生成的文件吗?你在GitHub或其他地方有代码吗?