Use gradle in eclipse to remotely publish web programs to tomcat

1. Download buildship in help -> Eclipse market in eclipse, as shown in the figure:

 

 



 

 

 

 

2. After installation, you can see gradle tasks, if you don't see it, you can find it in window ->show view -> other

 

 

 1: Double click on "war" is the packager.

2: Double-click "deploy" to publish the program.

 

3. Configure the content in build.gradle as follows:

 

 

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

                    '''

    }

  }

}

 

//Close and restart tomcat, copy the program

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'

    }

  }

}

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326489362&siteId=291194637