ant打包命令

学习ant打包命令。发布到以上tomcat还未做集成部署,无法添加到jenkins中。

 

http://blog.csdn.net/telnetor/article/details/7015935

http://www.blogjava.net/1504/archive/2009/04/15/265851.html

http://blog.csdn.net/arthur0088/article/details/5671888

http://zhouhaitao.iteye.com/blog/1142188

 

<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
上面的basedir怎么理解?表示基础目录,也就是源目录。

ant打包Dynamic Web Project生成war包的例子如下:

/**
 * 
 */
package oata;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
/**
 * @author Administrator
 *
 */
public class HelloWorld {

    static Logger logger = Logger.getLogger(HelloWorld.class);
    /**
     * @param args
     */
    public static void main(String[] args) {
        //System.out.println("Hello World");
        //BasicConfigurator.configure();
        logger.info("Hello World");          // the old SysO-statement
    }

}

log4j.properties文件如下:

log4j.rootLogger=DEBUG, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n


上面的META-INF在创建项目的时候本来里面是有内容的。

build.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" basedir="." default="main">

    <property name="src.dir"     value="src"/>
    <!-- lib.dir is right -->
    <property name="lib.dir"     value="WebContent/WEB-INF/lib"/>

    <property name="build.dir"   value="WebContent"/>
    <property name="classes.dir" value="WebContent/WEB-INF/classes"/>
    <property name="war.dir"     value="war"/>

    <property name="main-class"  value="oata.HelloWorld"/>

    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${war.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${lib.dir}"/>
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
        <!-- copy properties file of src folder -->
        <copy todir="${classes.dir}">
            <fileset dir="${src.dir}" excludes="**/*.java"/>
        </copy>
    </target>

    <target name="war" depends="compile">
        <mkdir dir="${war.dir}"/>
        <jar destfile="${war.dir}/${ant.project.name}.war" basedir="${build.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>

    <!-- <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
        <java fork="true" classname="${main-class}">
            <classpath>
                <path refid="classpath"/>
                <path location="${jar.dir}/${ant.project.name}.jar"/>
            </classpath>
        </java>
    </target> -->

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

    <target name="main" depends="clean,war"/>

</project>

进入目录

执行命令ant,即可。就会在war目录下面生成HelloWorld.war。

posted @ 2013-10-09 09:18  唾手可得的树  阅读(2619)  评论(0编辑  收藏  举报