简体   繁体   English

Tomcat无法启动Gradle Webapp

[英]Tomcat not booting up Gradle Webapp

I have a Gradle webapp having plugin war and jetty defined in build.gradle , as follows: 我有一个Gradle webapp ,在build.gradle中定义了插件warjetty ,如下所示:

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'

group = 'com.company'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
war.baseName = 'deploy'

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repository.pentaho.org/artifactory/repo/" }
}
dependencies {
    ..
}

When I perform a gradle build with jettyRunWar , as follows: 当我执行gradle这个构建jettyRunWar ,具体如下:

$ ./gradlew jettyRunWar

It build the application and deploy it to Jetty as expected. 它构建应用程序,然后按预期将其部署到Jetty。

Now I want to deploy the same application to Tomcat7 as well, to do the same, I ran the gradle war task as follows: 现在,我也想将相同的应用程序部署到Tomcat7 ,要执行相同的操作,我按如下方式运行gradle war任务:

$ ./gradlew war

after running the task, I can see the deploy-1.0.war inside /Users/ArpitAggarwal/deploy/build/libs/ and when I tried to deploy it to Tomcat7, it's not picked up by Tomcat. 运行任务之后,我可以在/Users/ArpitAggarwal/deploy/build/libs/看到deploy-1.0.war ,当我尝试将其部署到Tomcat7时,Tomcat并未将其拾取。

My question is - Do I need to apply any additional plugin to make the application deployable to Tomcat7? 我的问题是-我是否需要应用任何其他插件以使应用程序可部署到Tomcat7?

Thanks. 谢谢。

war plug-in only creates a war, it doesn't deploy generated war to tomcat by itself. war插件只会创建战争,它不会将生成的战争本身部署到tomcat。

You can create a task to deploy war to tomcat. 您可以创建任务以将战争部署到tomcat。

task deployToTomcat(type: Copy) {
    from war.archivePath
    into "${tomcatHome}/webapps"
}

You can also use gradle-tomcat-plugin . 您也可以使用gradle-tomcat-plugin

The problem is contextRoot of .war file. 问题是.war文件的contextRoot Gradle generates the contextRoot of .war file picking the war.baseName and version , so the contextRoot is changed to deploy-1.0 and the application is accessible at: Gradle会选择war.baseNameversion生成.war文件的contextRoot,因此contextRoot更改为deploy-1.0,并且可以在以下位置访问该应用程序:

localhost:8080/deploy-1.0

Then I removed the version field from build.gradle which makes Gradle generate .war with contextRoot as deploy and application accessibility at: 然后我从build.gradle删除了version字段,这使Gradle使用contextRoot作为部署和应用程序可访问性生成.war,位于:

localhost:8080/deploy/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM