eclipse 中使用gradle 远程发布web程序到tomcat

1.在eclipse 中的 help ->Eclipse market 中下载 buildship ,如图:

 

 



 

 

 

 

2.安装后就可以看到 gradle tasks , 如果没有看到 可以在 window ->show view -> other 中找到

 

 

 1: 双击 “war” 是打包程序。

2:双击“deploy” 是否发布程序。

 

3.在build.gradle  配置内容如下:

 

group 'com.cloudboce'

apply plugin: 'java'

apply plugin: 'war'

apply plugin: 'eclipse'

apply plugin: 'idea'

apply plugin: 'org.hidetake.ssh'

sourceCompatibility = 1.7

targetCompatibility = 1.7

version = '1.0'

jar {

    manifest {

        attributes 'Implementation-Title': 'Gradle Quickstart',

                'Implementation-Version': version

    }

}

configurations.all {

    resolutionStrategy.eachDependency { DependencyResolveDetails details ->

        if (details.requested.group == 'org.springframework') {

            details.useVersion '4.2.4.RELEASE'

        }

    }

    resolutionStrategy.eachDependency { DependencyResolveDetails details ->

        if (details.requested.group == 'commons-logging') {

            details.useVersion '1.2'

        }

    }

}

buildscript{

repositories {

jcenter()

     mavenCentral()

}

dependencies {

        classpath 'org.hidetake:gradle-ssh-plugin:2.6.0'

      }

}

repositories {

jcenter()

    mavenCentral()

}

dependencies {

    def springVersion = "4.2.4.RELEASE";

    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'

    testCompile group: 'junit', name: 'junit', version: '4.+'

    //core spring  

    compile "org.springframework:spring-context:$springVersion"

    compile "org.springframework:spring-core:$springVersion"

    compile "org.springframework:spring-webmvc:$springVersion"

    compile "org.springframework:spring-aop:$springVersion"

    //db access  

    compile "org.springframework:spring-jdbc:$springVersion"

    compile "org.springframework:spring-orm:$springVersion"

    //log4j2

    def log4j_version = "2.2";

    compile "org.apache.logging.log4j:log4j-api:$log4j_version"

    compile "org.apache.logging.log4j:log4j-core:$log4j_version"

    compile "org.apache.logging.log4j:log4j-web:$log4j_version"

    compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"

    //mybatis

    compile "org.mybatis:mybatis:3.2.8"

    compile "org.mybatis:mybatis-spring:1.2.2"

    // jackson

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.1'

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.1'

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.1'

   

    

}

test {

    systemProperties 'property': 'value'

}

uploadArchives {

    repositories {

        flatDir {

            dirs 'repos'

        }

    }

}

task copyJars(type: Copy) {

    from configurations.runtime

    into '/src/main/webapp/WEB-INF/lib'

}

ssh.settings {

  knownHosts = allowAnyHosts

}

remotes {

  deployServer {

    host = '192.168.66.124'

    user = 'root'

    password = '123456'

  }

}

war {

    archiveName 'server.war'

}

task shutdownTomcat() << {

  ssh.run {

    session(remotes.deployServer) {

      println 'shut down tomcat...' 

      executeScript '''#!/bin/sh

                        cd /opt/app/apache-tomcat-7.0.67/bin

                        ./shutdown.sh

                    '''

    }

  }

}

//对tomcat 关闭重启, 复制程序

task del(dependsOn:shutdownTomcat) << {

  ssh.run {

    session(remotes.deployServer) {

      println 'start deleting...' 

      executeScript '''#!/bin/sh

                        rm -rf /opt/app/apache-tomcat-7.0.67/webapps/server

                        rm -f /opt/app/apache-tomcat-7.0.67/webapps/server.war

                    '''

    }

  }

}

task copy(dependsOn:del) << {

  ssh.run {

    session(remotes.deployServer) {

      println 'start copying war...' 

      put from: buildDir.toString() + '/libs/cloud_server.war', into: '/opt/app/apache-tomcat-7.0.67/webapps'

    }

  }

}

task deploy(dependsOn:copy) << {

  ssh.run {

    session(remotes.deployServer) {

      println 'start tomcat...' 

      execute '/opt/app/apache-tomcat-7.0.67/bin/startup.sh'

    }

  }

}

 

 

猜你喜欢

转载自gjp014.iteye.com/blog/2358502