- 下载tomcat6:http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.41/bin/apache-tomcat-6.0.41.zip
- 解压Tomcat到服务器,本例子将tomcat解压在本地
- 修改%TOMCAT_HOME%/conf/tomcat-users.xml文件如下:
<tomcat-users> <role rolename="tomcat"/> <role rolename="manager"/> <user username="admin" password="admin" roles="tomcat,manager"/> </tomcat-users>
- 在gradle项目中引入gradle-cargo-plugin
apply plugin: 'com.bmuschko.cargo' apply plugin: 'com.bmuschko.cargo-base' buildscript { repositories { jcenter() } dependencies { classpath 'com.bmuschko:gradle-cargo-plugin:2.0.1' } }
- 配置cargo插件
cargo { containerId = 'tomcat6x' port = 8080 //服务器tomcat端口号 deployable { context = '/' } remote { hostname = "localhost"//服务器地址 username = "admin" //来源于tomcat-users.xml password = "admin" timeout = 6000 } }
- 重新配置war task只包含源码
war { classpath = classpath.filter { return !it.name.endsWith(".jar") } }
- 将所有的依赖包拷贝到服务器%TOMCAT_HOME%/lib目录下(本例子只依赖commons-io)
- 运行gradle war创建war文件
- 运行gradle cargoDeployRemote/cargoRedeployRemote
完整的build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.0.1'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'com.bmuschko.cargo-base'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'commons-io:commons-io:2.4'
}
war {
classpath = classpath.filter {
return !it.name.endsWith(".jar")
}
}
cargo {
containerId = 'tomcat6x'
port = 8080
deployable {
context = '/'
}
remote {
hostname = "localhost"
username = "admin"
password = "admin"
timeout = 6000
}
}