Ant编译项目一例,eclipse下,有svn代码管理。

myprj-build.properties:

build.home=./build
dist.home=./dist

app.name=myprj

junit.report.dir=./report/junit
coverage.report.dir=./report/coverage
myprj.lib.dir=./WEB-INF/lib
myprj.libtest.dir=./WEB-INF/libtest
findbugs.home=C:/findbugs-1.2.1
tomcat.home=D:/apache-tomcat-5.5.27

 

myprj-build.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="myprj" basedir="." default="war">

    <property file="myprj-build.properties"/>
    <!--
    <taskdef resource="checkstyletask.properties"
         classpath="${myprj.libtest.dir}/checkstyle-all-4.3.jar" />
    <taskdef resource="djunittasks.properties"
        classpath="${myprj.libtest.dir}/djunit.jar" />
    -->
    <path id="class.path">
        <fileset dir="${myprj.lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
        <!--
        <fileset dir="${myprj.libtest.dir}">
            <include name="**/*.jar"/>
        </fileset>
        -->
    </path>

    <!--=============== clean ===============-->
    <target name="prepare">
        <mkdir dir="${build.home}"/>
        <mkdir dir="${dist.home}"/>
    </target>

    <!--=============== clean ===============-->
    <target name="clean" depends="clean-build, clean-dist">
    </target>

    <!--=============== clean-build ===============-->
    <target name="clean-build">
        <delete dir="${build.home}"/>
    </target>

    <!--=============== clean-dist ===============-->
    <target name="clean-dist">
        <delete dir="${dist.home}"/>
    </target>

    <!--=============== compile ===============-->
    <target name="compile" depends="prepare">

        <mkdir dir="${build.home}/WEB-INF/classes"/>

        <copy todir="${build.home}" includeEmptyDirs="false" flatten="false">
            <fileset dir="." excludes="build/**,**/*.scc,WEB-INF/lib/servlet-api.jar,WEB-INF/lib/jsp-api.jar,WEB-INF/src/**,WEB-INF/srctest/**,WEB-INF/libtest/**,*.bat,*build*.xml,*build*.properties,.classpath,.project,docs/**,work/**,.checkstyle,.djunitplugin,.tomcatplugin,.fbprefs,.settings/**"/>
        </copy>
        <copy todir="${build.home}/WEB-INF/classes" includeEmptyDirs="false" flatten="false">
            <fileset dir="WEB-INF/src" excludes="**/*.scc, **/*.java, **/DaoContext.xml, **/ddl.txt"/>
        </copy>

        <javac srcdir="./WEB-INF/src"
              destdir="${build.home}/WEB-INF/classes"
                debug="on"
              target="1.6"
              source="1.6"
              encoding="UTF-8"
             optimize="true">
          <classpath refid="class.path"/>
        </javac>
    </target>

    <!--=============== war ===============-->
    <target name="war" depends="clean-dist, compile">
        <war destfile="${dist.home}/${app.name}.war" webxml="./WEB-INF/web.xml">
          <fileset dir="${build.home}"/>
        </war>
    </target>

    <!--=============== deploy ===============-->
    <target name="deploy" depends="war">
        <copy file="${build.home}/${app.name}.war" todir="${tomcat.home}/webapps"/>
    </target>

    <!--=============== undeploy ===============-->
    <target name="undeploy" depends="war">
        <delete file="${tomcat.home}/webapps/${app.name}.war"/>
        <delete dir="${tomcat.home}/webapps/${app.name}"/>
    </target>

    <!--=============== source ===============-->
    <target name="pkg-src">
        <jar destfile="${dist.home}/${app.name}-src.jar">
            <fileset dir="./WEB-INF/src" excludes="**/*.scc, **/ddl.txt, **/DaoContext.xml"/>
        </jar>
    </target>
    <!--=============== dist ===============-->
    <target name="dist" depends="war, pkg-src"/>


    <!--=============== compile-test ===============-->
    <target name="compile-test" depends="compile">

        <mkdir dir="${build.home}/WEB-INF/classes-test"/>

<!--
        <copy todir="${build.home}" includeEmptyDirs="false" flatten="false">
            <fileset dir="." excludes="build/**, **/*.scc, WEB-INF/lib/servlet-api.jar, WEB-INF/lib/jsp-api.jar, WEB-INF/src/**, WEB-INF/srctest/**, WEB-INF/libtest/**, *.bat, *build*.xml, *build*.properties, .classpath, .project, docs/**"/>
        </copy>
        <copy todir="${build.home}/WEB-INF/classes" includeEmptyDirs="false" flatten="false">
            <fileset dir="WEB-INF/src" excludes="**/*.scc, **/*.java, **/DaoContext.xml, **/ddl.txt"/>
        </copy>
-->
        <javac srcdir="./WEB-INF/srctest"
              destdir="${build.home}/WEB-INF/classes-test"
                debug="off"
               target="1.6"
               source="1.6"
             encoding="UTF-8"
             optimize="true">
          <classpath refid="class.path"/>
          <classpath path="${build.home}/WEB-INF/classes"/>
        </javac>
    </target>

    <!--=============== test ===============-->
    <target name="djunit.test" depends="compile-test">
        <delete dir="${junit.report.dir}"/>
        <mkdir dir="${junit.report.dir}"/>

        <djunit printsummary="yes" targetsrcdir="./WEB-INF/src" virtualmock="yes" coverage="yes">
            <jvmarg value="-Djp.co.dgic.eclipse.classloader.bytecodelibrary=BCEL"/>
            <classpath refid="class.path"/>
            <classpath path="${build.home}/WEB-INF/classes"/>
            <formatter type="xml"/>
            <batchtest todir="${junit.report.dir}">
                <fileset dir="${build.home}/WEB-INF/classes-test">
                    <include name="**/*Test.class"/>
                </fileset>
            </batchtest>
        </djunit>
        <junitreport>
            <fileset dir="${junit.report.dir}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.report.dir}"/>
        </junitreport>
    </target>

    <!--=============== djUnit Coverage Report ===============-->
    <target name="djunit.report" depends="djunit.test">
        <delete dir="${coverage.report.dir}"/>
        <mkdir dir="${coverage.report.dir}"/>

        <djunit-coverage-report serFile="./jcoverage.ser" srcdir="./WEB-INF/srctest" destdir="${coverage.report.dir}">
            <classpath refid="class.path"/>
            <classpath path="${build.home}/WEB-INF/classes"/>
        </djunit-coverage-report>
    </target>

    <!--=============== CheckStyle ===============-->
    <target name="checkstyle"
            description="Generates a report of code convention violations.">

        <checkstyle config="docs/myprj_CheckStyle.xml"
                  failureProperty="checkstyle.failure"
                  failOnViolation="false">
            <formatter type="xml" tofile="checkstyle_report.xml"/>
            <fileset dir="./WEB-INF/src" includes="**/*.java"/>
      </checkstyle>

      <style in="checkstyle_report.xml" out="checkstyle_report.html" style="docs/checkstyle.xsl"/>

    </target>

    <!-- run this target as part of automated build -->
    <target name="checkstyle-nightly"
            depends="checkstyle"
            if="checkstyle.failure"
            description="Sends email if checkstyle detected code conventions violations.">

      <!-- use your own server and email addresses below. See Ant documentation for details -->

      <mail from="[email protected]"
            tolist="[email protected],[email protected]"
            mailhost="mailbox.some.domain"
            subject="Checkstyle violation(s) in project ${ant.project.name}"
            files="checkstyle_report.html"/>

    </target>

    <!--=============== FindBugs ===============-->
    <!--
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>

    <target name="findbugs" depends="compile">
        <findbugs home="${findbugs.home}"
                  output="xml"
                  outputFile="bcel-fb.xml" >
          <auxClasspath path="${basedir}/lib/Regex.jar" />
          <sourcePath path="${basedir}/WEB-INF/src" />
          <class location="${basedir}/WEB-INF/libtest/bcel-5.2.jar" />
        </findbugs>
    </target>
    -->
</project>

在eclipse里,直接运行run as ant build就可以,生成build和dist文件夹:

 

 

Buildfile: D:\workspace_myprj_3.2\myprj\myprj-build-default.xml
clean-dist:
prepare:
    [mkdir] Created dir: D:\workspace_myprj_3.2\myprj\build
    [mkdir] Created dir: D:\workspace_myprj_3.2\myprj\dist
compile:
    [mkdir] Created dir: D:\workspace_myprj_3.2\myprj\build\WEB-INF\classes
     [copy] Copying 4317 files to D:\workspace_myprj_3.2\myprj\build
war:
      [war] Building war: D:\workspace_myprj_3.2\myprj\dist\myprj.war
      [war] Warning: selected war files include a WEB-INF/web.xml which will be ignored (please use webxml attribute to war task)
BUILD SUCCESSFUL
Total time: 3 minutes 50 seconds

你可能感兴趣的:(eclipse,Web,ant,SVN,项目管理)