Maven部署到多个Tomcat服务器 [英] Maven Deploy To Multiple Tomcat Servers

查看:85
本文介绍了Maven部署到多个Tomcat服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用可编写的maven将战争部署到多个tomcat服务器的最简单的例子是什么?

我尝试了以下URL并询问了邮件列表,但没有提出任何简短且可以正常使用的内容.

该示例应在示例中的某个位置定义服务器(带有示例用户名/密码)

解决方案

Markus Lux的想法也可以通过配置文件管理与Maven2解决方案一起应用:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
        </plugin>
    </plugins>
    ...
</build>
<profiles>
    <profile>
        <id>env-foo1</id>
        <!-- Activated when -Denv=foo1 is given as parameter. -->
        <activation>
            <property>
                <name>env</name>
                <value>foo1</value>
            </property>
        </activation>
        <properties>
            <deploy.env>xxx</deploy.env>
            <tomcat.manager>http://foo1/manager</tomcat.manager>
            <tomcat.manager.username>foo</tomcat.manager.username>
            <tomcat.manager.password>bar</tomcat.manager.password>
        </properties>
    </profile> 
    <profile>
        <id>env-foo2</id>
        <!-- Activated when -Denv=foo2 is given as parameter. -->
        <activation>
            <property>
                <name>env</name>
                <value>foo2</value>
            </property>
        </activation>
        <properties>
            <deploy.env>dev</deploy.env>
            <tomcat.manager>http://foo2/manager</tomcat.manager>
            <tomcat.manager.username>foo</tomcat.manager.username>
            <tomcat.manager.password>bar</tomcat.manager.password>
        </properties>
    </profile>
    ... 
</profiles>    

然后,您只需要使用适当的参数( -Denv = foo1 -Denv = foo2 ,...)


除此之外,您还可以使用 Hudson 连续集成的矩阵功能来增强此解决方案服务器.我在此处给出了简短的解释.. >

基本上,您只需要在Hudson中定义一个常规" Maven2作业,就可以使用Matrix功能使Hudson多次运行此作业,每个环境一次.换句话说,您创建Hudson作业,然后使用 env 参数的所有可能值定义环境轴":

  • foo1
  • foo2
  • foo3
  • ...
然后

Hudson将使用 mvn 命令并使用参数 -Denv = foo1 来构建应用程序.一旦构建完成,它将构建相同的应用程序,但使用参数 -Denv = foo2 ,依此类推...

通过这种方式,哈德森将在各种环境中部署您的应用程序...

我希望我的解决方案能够帮助您实现目标...

What is the most minimal example of deploying a war to multiple tomcat servers using maven that can be written?

I've tried the following URLs and asked the mailing list, but not coming up with anything that was short and would simply work.

The example should have the servers defined in the example somewhere (with sample usernames/passwords)

解决方案

The idea of Markus Lux can be also applied with a Maven2 solution, with the profiles management:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
        </plugin>
    </plugins>
    ...
</build>
<profiles>
    <profile>
        <id>env-foo1</id>
        <!-- Activated when -Denv=foo1 is given as parameter. -->
        <activation>
            <property>
                <name>env</name>
                <value>foo1</value>
            </property>
        </activation>
        <properties>
            <deploy.env>xxx</deploy.env>
            <tomcat.manager>http://foo1/manager</tomcat.manager>
            <tomcat.manager.username>foo</tomcat.manager.username>
            <tomcat.manager.password>bar</tomcat.manager.password>
        </properties>
    </profile> 
    <profile>
        <id>env-foo2</id>
        <!-- Activated when -Denv=foo2 is given as parameter. -->
        <activation>
            <property>
                <name>env</name>
                <value>foo2</value>
            </property>
        </activation>
        <properties>
            <deploy.env>dev</deploy.env>
            <tomcat.manager>http://foo2/manager</tomcat.manager>
            <tomcat.manager.username>foo</tomcat.manager.username>
            <tomcat.manager.password>bar</tomcat.manager.password>
        </properties>
    </profile>
    ... 
</profiles>    

Then, you will just need to run X times the mvn command, with the adequate parameter (-Denv=foo1, -Denv=foo2,...)


In addition to that, you can enhance this solution by using the Matrix feature of the Hudson Continuous Integration server. I gave a short explanation about this feature here.

Basically, you just define a "normal" Maven2 job in Hudson, and with the Matrix feature, you can ask Hudson to run this job several times, one per environment. In others words, you create your Hudson job, and then you define the "environment axis" with all possible value for the env parameter:

  • foo1
  • foo2
  • foo3
  • ...

Hudson will then build the application with the mvn command and with the parameter -Denv=foo1.Once this build is finished, it will build the same application but with the parameter -Denv=foo2, and so on...

This way, Hudson will deploy your application in every environments...

I hope my solution will help you to reach your goals...

这篇关于Maven部署到多个Tomcat服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆