Java持续集成(5) – 构建遵循WAR目录规范的Web工程

有时工程并非遵循Maven目录规范的,而是遵循war[Web Application Archie file]目录规范

开发方面,使用Sysdeo Eclipse Tomcat Launcher plugin支持开发、调试

使用此目录结构的好处是直观,即所有文件和最终在服务器上运行时的目录结构一致

坏处是不太好用Maven进行管理

 

构建此类工程的一般步骤

1. Jenkins从SVN拉取最新代码

2. 使用Ant脚本完成构建、部署

1) 编译WEB-INF/src下的所有java源码到WEB-INF/classes

2) 将WEB-INF/src下所有非java文件拷贝到WEB-INF/classes

3) 将整个工程打包成war

4) 通过TCD[Tomcat Client Deployer]发布工程到服务器

 

Ant构建、部署脚本示例

<?xml version="1.0"?>

<project name="test" basedir="." default="redeploy" xmlns:artifact="urn:maven-artifact-ant">



    <!-- Configure properties to access the Manager application -->

    <property name="path"     value=""/>

    <property name="url"      value="http://localhost:8080/manager/text"/>

    <property name="username" value="tomcat"/>

    <property name="password" value="tomcat"/>

    <property name="runtime-lib" value="D:\test\lib"/>



    <path id="deployer.classpath">

        <fileset dir="${runtime-lib}">

            <include name="*.jar"/>

        </fileset>

    </path>



    <!-- Configure the custom Ant tasks for the Manager application -->

    <taskdef resource="org/apache/catalina/ant/catalina.tasks"

            classpathref="deployer.classpath"/>



    <target name="redeploy">

        <delete dir="target" />

        <delete dir="WEB-INF/classes" />

        <mkdir dir="target"/>

        <mkdir dir="WEB-INF/classes"/>

        

        

        <javac destdir="WEB-INF/classes" 

            optimize="off" 

            debug="on" 

            failonerror="false" 

            srcdir="WEB-INF/src" 

            encoding="UTF-8" 

            excludes="**/*.smap">

          <compilerarg value="-Xlint:unchecked"/>

          <classpath>

            <fileset dir="WEB-INF/lib">

              <include name="*.jar"/>

            </fileset>

            <fileset dir="${runtime-lib}">

              <include name="*.jar"/>

            </fileset>

          </classpath>

          <include name="**/*.java" />

        </javac>

        

        <copy todir="WEB-INF/classes">

          <fileset dir="WEB-INF/src">

            <exclude name="**/*.java" />

          </fileset>

        </copy>

        

        <jar destfile="target/test.war">

            <fileset dir="${basedir}">

                <exclude name="axis2-web/**" />

                <exclude name="target/**" />

                <exclude name="work/**" />

                <exclude name=".classpath" />

                <exclude name=".project" />

                <exclude name=".tomcatplugin" />

                <exclude name="WEB-INF/src/**" />

                <exclude name="WEB-INF/test/**" />

                <exclude name="pom.xml" />

                <exclude name="build.xml" />

                <exclude name="build.properties" />

            </fileset>

        </jar>



        <deploy url="${url}" username="${username}" password="${password}"

              path="${path}" war="target/test.war" update="true" />

    </target>

</project>

【注】

1 ${runtime-lib}中存放的是从TCD压缩包中解压后的lib目录下的所有jar

下载地址

http://tomcat.apache.org/download-70.cgi

http://tomcat.apache.org/download-80.cgi

 

image

你可能感兴趣的:(java)