7.3.5. WAR deployment to Tomcat Linux Service

The example below has been tested on Ubuntu 16.04

  1. Add the buildWar task to the end of build.gradle. You can also specify a different context.xml file to setup the connection to the production database:

    task buildWar(type: CubaWarBuilding) {
        appHome = '${catalina.base}/work'
        singleWar = true
        includeContextXml = true
        includeJdbcDriver = true
        appProperties = ['cuba.automaticDatabaseUpdate': true]
        webXmlPath = 'modules/web/web/WEB-INF/single-war-web.xml'
        coreContextXmlPath = 'modules/core/web/META-INF/war-context.xml'
    }

    If the target server parameters differ from what you have on the local Tomcat used for fast deployment, provide appropriate application properties. For example, if the target server runs on port 9999, the task definition should be as follows:

    task buildWar(type: CubaWarBuilding) {
        appHome = './app_home'
        singleWar = false
        includeContextXml = true
        includeJdbcDriver = true
        appProperties = [
            'cuba.automaticDatabaseUpdate': true,
            'cuba.webPort': 9999,
            'cuba.connectionUrlList': 'http://localhost:9999/app-core'
        ]
    }
  2. Run the buildWar gradle task. As a result, app.war file will be generated in the build/distibutions directory of your project.

    gradlew buildWar
  3. Install Tomcat 8 Linux Service:

    sudo apt-get install tomcat8
  4. Copy the generated app.war file to the empty /var/lib/tomcat8/webapps directory of the server.

    Tip

    Tomcat service runs from tomcat8 user by default. The owner of webapps folder is tomcat8 as well.

  5. Create configuration file /usr/share/tomcat8/bin/setenv.sh with the following text:

    export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
  6. Restart the Tomcat service:

    sudo service tomcat8 restart
  7. Open http://localhost:8080/app in your web browser.