5.3.4. 部署 WAR 至 Tomcat Windows 服务
在 build.gradle 末尾添加 buildWar 任务:
task buildWar(type: CubaWarBuilding) {
appHome = './app_home'
singleWar = false
includeContextXml = true
includeJdbcDriver = true
appProperties = ['cuba.automaticDatabaseUpdate': true]
}
如果目标 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'
]
}
可以指定另外一个
context.xml
文件用来设置生产环境的数据库,示例:task buildWar(type: CubaWarBuilding) {
appHome = './app_home'
singleWar = false
includeContextXml = true
includeJdbcDriver = true
appProperties = ['cuba.automaticDatabaseUpdate': true]
coreContextXmlPath = 'modules/core/web/META-INF/production-context.xml'
}
执行
buildWar
Gradle 任务。会在项目build/distributions
目录生成app.war
和app-core.war
文件。gradlew buildWar
下载并执行 Tomcat 8 Windows Service Installer。
切换到安装好的服务的
bin
目录,使用管理员权限执行tomcat8w.exe
。 在 Java 标签页,设置 Maximum memory pool 为 1024MB。然后在 General 标签页重启服务。在 Java Options 字段添加
-Dfile.encoding=UTF-8
。拷贝项目生成的
app.war
和app-core.war
文件到 Tomcat 服务的webapps
目录。启动 Tomcat 服务。
在浏览器打开
http://localhost:8080/app
。