5.3.5. 部署 WAR 至 Tomcat Linux 服务
以下示例在 Ubuntu 16.04 测试通过
-
在 build.gradle 末尾添加 buildWar 任务。可以指定不同的
context.xml文件来设置生产环境数据库连接: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' }如果目标 Tomcat 服务的参数跟快速部署里用到的本地 Tomcat 的参数不同,需要提供相应的应用程序属性。比如,如果目标 Tomcat 运行在 9999 端口,任务定义会是这样:
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' ] } -
执行
buildWarGradle 任务。会在项目build/distributions目录生成app.war文件。gradlew buildWar -
安装 Tomcat 8 Linux Service:
sudo apt-get install tomcat8 -
拷贝项目生成的
app.war文件到 Tomcat 服务的/var/lib/tomcat8/webapps目录。Tomcat 服务默认是使用
tomcat8用户来启动的。所以webapps目录的所有者也是tomcat8。 -
创建配置文件
/usr/share/tomcat8/bin/setenv.sh包含以下设置:export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m" -
重启 Tomcat 服务:
sudo service tomcat8 restart -
在浏览器打开
http://localhost:8080/app。