5.3.5. WAR deployment to Tomcat Linux Service
The example below has been tested on Ubuntu 16.04
-
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' ] }
-
Run the
buildWar
gradle task. As a result,app.war
file will be generated in thebuild/distibutions
directory of your project.gradlew buildWar
-
Install Tomcat 8 Linux Service:
sudo apt-get install tomcat8
-
Copy the generated
app.war
file to the empty/var/lib/tomcat8/webapps
directory of the server.Tomcat service runs from
tomcat8
user by default. The owner ofwebapps
folder istomcat8
as well. -
Create configuration file
/usr/share/tomcat8/bin/setenv.sh
with the following text:export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
-
Restart the Tomcat service:
sudo service tomcat8 restart
-
Open
http://localhost:8080/app
in your web browser.