简体   繁体   English

如何使用Eclipse将Gradle Web应用程序部署到tomcat

[英]How to deploy my gradle web app to tomcat using eclipse

I'm trying to understand the way gradle work with eclipse. 我正在尝试了解Gradle与Eclipse一起工作的方式。

I can't figure out how to add my webb app to the tomcat server. 我不知道如何将Webb应用程序添加到tomcat服务器。 It does not appear. 它不会出现。

Some mention cargo plugin but i can't get it to work either. 有人提到货运插件,但我也无法使它正常工作。

Here are my plugins : 这是我的插件:

apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'

May be I am late in joining the party but it may help some one else. 我加入该党可能迟到了,但可能会对其他人有所帮助。

Actually there is no need for `apply plugin: 'eclipse-wtp'. 实际上,不需要`apply plugin:'eclipse-wtp'。

A cargo plugin is useful for deploying application using gradle. 货物插件对于使用gradle部署应用程序很有用。

Some incites from cargo documentation: 货物文件中的一些内容:

The plugin provides deployment capabilities for web applications to local and remote containers in any given Gradle build by leveraging the Cargo Ant tasks. 该插件通过利用Cargo Ant任务为任何给定的Gradle构建提供了将Web应用程序部署到本地和远程容器的功能。 The plugin supports WAR and EAR artifacts. 该插件支持WAR和EAR工件。

Starting with technical parts: 从技术部分开始:

Step 1: You need to add the below two imports in your gradle scripts. 步骤1:您需要在gradle脚本中添加以下两个导入。 It will enable the cargo plugin for your build. 它将为您的构建启用货运插件。

apply plugin: 'com.bmuschko.cargo'
apply plugin: 'com.bmuschko.tomcat'

Step 2: Specify the dependencies in your buildscripts 步骤2:在构建脚本中指定依赖项

buildscript {

    dependencies {
         classpath 'com.bmuschko:gradle-cargo-plugin:2.2.3'
         classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'

    }
}

Step 3: Add the dependencies for the tomcat and cargo 步骤3:添加Tomcat和货物的依赖项

dependencies {
    def tomcatVersion = '7.0.47'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
           "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
           "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"

    def cargoVersion = '1.4.5'
    cargo ("org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
          "org.codehaus.cargo:cargo-ant:$cargoVersion")
}

Step 4: Download the tomcat zip file and extract it in some folder in your local. 步骤4:下载tomcat zip文件并将其解压缩到本地的某个文件夹中。 Add the following code to your build.gradle 将以下代码添加到您的build.gradle中

cargo {
    containerId = 'tomcat7x'
    port = 9090

    deployable {

        file = new File('C:/<path-to-your-war-file>/gradleTutorial.war')
        context = 'gradleTutorial'
    }

    local {
        homeDir = file('C:/<path-to-the-extracted-tomcat-folder>/tomcat-7.0.47')
        outputFile = file('build/output.log')
        timeout = 60000

        containerProperties {
            property 'cargo.tomcat.ajp.port', 9099
        }
    }   
}

Step 4: configure your tomcat as follows: 步骤4:按以下步骤配置您的tomcat:

tomcat {
    httpPort = 9090
    httpsPort = 9091
    enableSSL = true
    contextPath = 'gradleTutorial'

}

Thats all. 就这样。 Once these steps are done. 一旦完成这些步骤。 You must need to install gradle plugin in your eclipse from market place and you can configure as below screenshot 您必须从市场上的日食中安装gradle插件,并且可以按以下屏幕截图进行配置

Eclipse configuration sample Eclipse配置样本

Enjoy...!!!!! 请享用...!!!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM