5.3.4. WAR deployment to Tomcat Windows Service

  1. Use the CUBA project tree > Project > Deployment > WAR Settings dialog in Studio or just manually add the buildWar task to the end of build.gradle:

    task buildWar(type: CubaWarBuilding) {
        appHome = '${app.home}'
        singleWar = true
        includeContextXml = true
        includeJdbcDriver = true
        appProperties = ['cuba.automaticDatabaseUpdate': true]
    }

    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 and you build separate WARs, 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'
        ]
    }

    You can also specify a separate context.xml file to setup the connection to the production database or provide that file later on the server:

    task buildWar(type: CubaWarBuilding) {
        appHome = '${app.home}'
        singleWar = true
        includeContextXml = true
        includeJdbcDriver = true
        appProperties = ['cuba.automaticDatabaseUpdate': true]
        coreContextXmlPath = 'modules/core/web/META-INF/war-context.xml'
    }
  2. Run the buildWar Gradle task. As a result, app.war file (or several files if you build separate WARs) will be generated in the build/distributions directory of your project.

    gradlew buildWar
  3. Create the application home directory, e.g. C:\app_home.

  4. Download and install the Tomcat 9 Windows Service Installer from the Apache Tomcat official site.

  5. Go to the bin directory of the installed server and run tomcat9w.exe with the administrative rights in order to set Tomcat service settings:

    1. Set Maximum memory pool to 1024MB on the Java tab.

    2. Instruct Tomcat to use UTF-8 encoding by adding -Dfile.encoding=UTF-8 to the Java Options field.

    3. Specify application home folder by adding the -Dapp.home=c:/app_home to the Java Options field.

      tomcat service settings
  6. If you want to provide production database connection properties with a local file on the server, you can create a file in the conf\Catalina\localhost subfolder of the Tomcat server. The name of the file depends on the WAR file name, e.g. app.xml for single WAR and app-core.xml if separate WAR files are deployed. Copy contents of the context.xml to this file.

  7. With the default configuration all application log messages are appended to the logs/tomcat9-stdout.log file. You have two options how to customize logging configuration of the application:

    • Create the logback configuration file in the project. Specify path to this file for the logbackConfigurationFile parameter of the buildWar task (manually or with the help of Studio WAR Settings dialog).

    • Create the logging configuration file on the production server.

      Copy the logback.xml file from the development Tomcat (deploy/tomcat/conf project sub-folder) to the application home directory and edit the logDir property in this file:

      <property name="logDir" value="${app.home}/logs"/>

      Add the following line to the Java Options field in the Tomcat 9 Windows Service settings window to specify path to the logging configuration file:

      -Dlogback.configurationFile=C:/app_home/logback.xml
  8. Copy the generated WAR file(s) to the webapps directory of the Tomcat server.

  9. Restart the Tomcat service.

  10. Open http://localhost:8080/app in your web browser.