Search code examples
eclipsetomcatgradlebuild.gradlegradlew

Tomcat not booting up Gradle Webapp


I have a Gradle webapp having plugin war and jetty defined in build.gradle, as follows:

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:

$ ./gradlew jettyRunWar

It build the application and deploy it to Jetty as expected.

Now I want to deploy the same application to Tomcat7 as well, to do the same, I ran the gradle war task as follows:

$ ./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.

My question is - Do I need to apply any additional plugin to make the application deployable to Tomcat7?

Thanks.


Solution

  • war plug-in only creates a war, it doesn't deploy generated war to tomcat by itself.

    You can create a task to deploy war to tomcat.

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

    You can also use gradle-tomcat-plugin.