使用hudson创建和部署war文件

时间:2012-12-14 08:50:15

标签: hudson

我想用hudson创建一个war文件。我做了以下步骤。

1.我已在项目中创建了build.xml。

2.在那个ant文件中,我提供了编译应用程序和创建战争的目标。

3.然后我创建了hudson作业,我提供了构建选项,即由ant调用。在部署选项中,我提供了我必须部署战争的weContainer。

4.创建战争并将其部署在webcontainer上。

但这是正确的方法吗?

谢谢,

1 个答案:

答案 0 :(得分:1)

您可以使用maven货运插件和复制工件插件来使用hudson部署战争。 提供服务器管理员。在apache tomcat中添加用户。

<!-- Configuration for the Maven build -->
<build>
    <!-- The plugins tag as mandated by maven -->
    <plugins>
        <!-- Start's the plugin tag for Cargo! -->
        <plugin>
            <!-- Cargo Group Id -->
            <groupId>org.codehaus.cargo</groupId>
            <!-- Cargo's Artifact Id -->
            <artifactId>cargo-maven2-plugin</artifactId>
            <!-- This the most important part of the setup -->
            <configuration>
                <!--
                    When Cargo starts the container, the following tag instructs it to
                    wait for you to kill the session with Crtl-C
                -->
                <wait>true</wait>
                <!--
                    The following tag details the container you want to
                    deploy to.
                -->
                <container>
                    <!--
                        Specifying "tomcat6x" is very important! This one tripped me up
                        for quite a while. The issue is that instead of being an
                        identifier for you, "tomcat6x" is an identifier for Cargo that
                        you want to deploy your webapp in Tomcat 6.x. I had initially
                        thought otherwise and hence just dropped the 'x', making it
                        "tomcat6", but that never worked.
                    -->
                    <containerId>tomcat6x</containerId>
                    <!--
                        Type == Installed means that you want to deploy to a container
                        that's installed on your computer
                    -->
                    <type>installed</type>
                    <!-- The home folder for your local Tomcat -->
                    <home>${catalina.home}</home>
                </container>
                <configuration>
                    <!--
                        This is another one that confused me for long. Its not enough to
                        specify 'installed' in the container tag. You have to now specify
                        another configuration with type == existing and re-issue the home
                        path
                    -->
                    <type>existing</type>
                    <home>${catalina.home}</home>
                </configuration>
                <!--
                    Cargo has the notion of a 'deployer' in which you specify
                    'deployables'
                -->
                <deployer>
                    <!-- You have to again specify that the type for the deployer -->
                    <type>installed</type>
                    <deployables>
                        <!-- This deployable specifies the webapp you want to deploy -->
                        <deployable>
                            <groupId>com.dpillay.oworld</groupId>
                            <artifactId>oworld-webapp</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </deployer>
            </configuration>
            <!--
                Executions specify the targets that you want to run during build
            -->
            <executions>
                <!--
                    Maven has the concept of a 'phase' which can be thought of a
                    collection of goals. Hence here we are specifying that during the
                    'install' phase first deploy the webapp to the container specific
                    folder and then start the container. Both 'deployer-deploy' and
                    'start' are cargo specific goals.
                -->
                <execution>
                    <id>verify-deploy</id>
                    <phase>install</phase>
                    <goals>
                        <goal>deployer-deploy</goal>
                        <goal>start</goal>
                    </goals>
                </execution>
                <!--
                    Specifying that during the 'pre-clean' phase, Cargo should first
                    stop the container.
                -->
                <execution>
                    <id>clean-undeploy</id>
                    <phase>pre-clean</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>