zoukankan      html  css  js  c++  java
  • Maven Web项目使用Cargo实现自动化部署

    在pom.xml中配置Cargo相关信息

    一、部署到本地Web容器

    1、使用standalone模式

    在pom.xml配置下面代码:

    <build>
    <finalName>WebProject</finalName>
    build>
    <finalName>WebProject</finalName>

    <plugins>

    <plugin>

    <groupId>org.codehaus.cargo</groupId>

    <artifactId>cargo-maven2-plugin</artifactId>

    <version>1.6.0</version>

    <configuration>

    <container>

    <containerId>tomcat7x</containerId>

    <home>D:JAVAapache-tomcat-7.0.70</home>

    </container>

    <configuration>

    <type>standalone</type>

    <home>${project.bulid.directory}/tomcat7x</home>

    </configuration>

    </configuration>

    </plugin>

    </plugins>

    </build>
    1、finalName:表示部署的项目名称,即war包名称也可以不声明;
    2、在cargo-maven2-plugin中有两个配置,container(容器)、configuration(配置信息);
        1)container容器:指定Web容器的名称和路径
            【1】containerId表示容器的类型,
            【2】home表示容器的安装目录,
            【3】type可以不声明,取默认值installed;
        2)configuration:用于配置部署的模式及复制容器配置到什么位置,
    【1】type:部署模式,有三种值【standalone,existing,runtime】,runtime用于远程部署
        <type>standalone</type>:将指定的web容器配置信息复制到指定路径,并将部署应用到指定路径;
        <type>existing</type>:将应用部署到现有的web容器中,不需要重新复制容器的配置信息;
        <type>runtime</type>:既不使用独立的容器配置,也不使用本地现有的容器配置,而是依赖一个已运行的容器。
    【2】home:指定路径,部署应用的路径
    3、${project.bulid.directory}:表示当前项目下target目录

    将上述代码放入pom.xml文件保存后,执行mvn install,然后打开命令窗口,进入到项目的目录下,输入命令:mvn cargo:run,如果构建成功并启动成功,就可以访问项目路径了【http://localhost:8080/WebProject/】;

    在项目上的变化,在target目录下多一个文件夹tomcat7,里面存放了从Tomcat中复制过来的配置信息和部署应用的war包,Tomcat安装目录下的webapps没有war包。

    2、使用existing模式

    在pom.xml中加入下面代码:

    <build>

    <finalName>WebProject</finalName>

    <plugins>

    <plugin>

    <groupId>org.codehaus.cargo</groupId>

    <artifactId>cargo-maven2-plugin</artifactId>

    <version>1.6.0</version>

    <configuration>

    <container>

    <containerId>tomcat7x</containerId>

    <home>D:JAVAapache-tomcat-7.0.70</home>

    </container>

    <configuration>

    <type>exsiting</type>

    <home>D:JAVAapache-tomcat-7.0.70</home>

    </configuration>

    </configuration>

    </plugin>

    </plugins>

    </build>
     

    将上述代码放入pom.xml文件保存后,执行mvn install,然后打开命令窗口,进入到项目的目录下,输入命令:mvn cargo:run,如果构建成功并启动成功,就可以访问项目路径了【http://localhost:8080/WebProject/】;

    在Tomcat安装目录下webapps中可以查看到war包信息,项目的target目录下没有多余的信息。

    二、部署到远程Web容器

    <build>

    <finalName>WebProject</finalName>

    <plugins>

    <plugin>

    <groupId>org.codehaus.cargo</groupId>

    <artifactId>cargo-maven2-plugin</artifactId>

    <version>1.6.0</version>

    <configuration>

    <container>

    <containerId>tomcat7x</containerId>

    <type>remote</type>

    </container>

    <configuration>

    <type>runtime</type>

    <properties>

    <cargo.remote.username>tomcat</cargo.remote.username>

    <cargo.remote.password>123456</cargo.remote.password>

    <cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url>

    </properties>

    </configuration>

    </configuration>

    </plugin>

    </plugins>

    </build>
     

    上述代码:模拟访问本地Tomcat的管理地址【http://localhost:8080/manager】,tomcat manager默认情况下是禁止访问的,需要先进行用户和权限的配置,在conf/tomcat-users.xml中设置用户名、密码及用户权限

    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <role rolename="manager-jmx"/>
    <role rolename="manager-status"/>
    <user username="tomcat" password="123456" roles="manager-gui,manager-script,manager-jmx"/>
     

    container中的type必须配置为remote,表示不需要安装目录或者安装包

    configuration中的type需要配置为runtime,表示既不使用独立的容器配置,也不是使用本地现有的容器配置,而是依赖一个已运行的容器;properties用于声明一些热部署(热部署:能够将部署或取消部署到正在运行的容器中)相关的配置信息,比如在容器中声明容器类型是tomcat7x,需要指定tomcat的用户名、密码以及管理地址。

    自动部署到远程Web容器的运行命令:mvn cargo:redeploy    
    ————————————————
    版权声明:本文为CSDN博主「学之以恒_大道至简」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/cb_lcl/article/details/80960587

  • 相关阅读:
    分享一个新软件 云端软件平台+个人使用心得
    扩展easyui.datagrid,添加数据loading遮罩
    在Flash中结合webservice 实现无缝滚动效果
    使用HttpWebRequest访问Web服务,并传递Cookie数据
    批量生成一组不同随机字符串
    文章分享代码
    jQuery.easyui与jQuery UI冲突
    转换BBSXP 2008到Discuz X1.5部分问题解决记录
    在ASP.NET的server form 中使用easyui的layout布局控件
    神奇3D圣诞树高超的技术!
  • 原文地址:https://www.cnblogs.com/wangwenlong8/p/13022176.html
Copyright © 2011-2022 走看看