ant 学习笔记(Ant来打包)

在拜读了http://dev.csdn.net/author/glchengang/878b7b8c76944defa9dbdb8ed8a8b89a.html一篇文章后,在自己机子上练习一下,为了适合自己工程需要,具体build.xml做了小的修改。共遇到两个问题:

 

1)ant里未加入tool.jar包问题:

    现象:BUILD FAILED E:/eclipse/workspace/test/build.xml:68: Unable to find a javac compiler;

    解决方法:eclipse中,选择 窗口/首选项/ant/运行时 在其中将jkd中的tool.jar引入

2)ant 生成javadoc问题:

    现象:E:/eclipse/workspace/struts1.2/build.xml:128: Javadoc failed: java.io.IOException: CreateProcess: javadoc.exe -d D:/dist/api -use -windowtitle "STRUTS1.2 API" -doctitle " <h1>STRUTS1.2 Project </h1>" -bottom " <i>Document by Anhuixiao 2010. </i>" -classpath E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-antlr.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-bcel.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-bsf.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-log4j.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-oro.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-regexp.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-apache-resolver.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-commons-logging.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-commons-net.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-icontract.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-jai.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib/ant-javamail.jar;E:/eclipse/plugins/org.apache.ant_1.6.5/lib?

Total time: 6 seconds 
    解决方法:<javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="STRUTS1.2 API" useexternalfile="yes">加入加粗部分即可解决

下面是build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="myswt project" default="api_doc">

    <!-- 定义目录变量 -->

    <property name="src.dir" value="src"/>

    <property name="bin.dir" value="WEB-INF/classes"/>

    <property name="lib.dir" value="WEB-INF/lib"/>

    <property name="dist.dir" value="d:/dist"/>

    <property name="doc.dir" value="${dist.dir}/api"/>

    <property name="jsp.dir" value="kikan.jsp"/>

    <!-- 定义编译文件时所引用的库 -->

    <path id="master-classpath">

        <fileset dir="${lib.dir}" id="project_lib">

            <include name="servlet-api.jar"/>

            <include name="jasper-runtime.jar"/>

            <include name="jsp-api.jar"/>

            <include name="antlr.jar"/>

            <include name="commons-beanutils.jar"/>

            <include name="commons-digester.jar"/>

            <include name="commons-fileupload.jar"/>

            <include name="commons-logging.jar"/>

            <include name="commons-validator.jar"/>

            <include name="jakarta-oro.jar"/>

            <include name="mysql-connector-java-5.0.6-bin.jar"/>

            <include name="struts.jar" />
           
        </fileset>

    </path>

    <!-- 首任务(空)-->

    <target name="init"/>

    <!-- 编译 -->

    <target name="compile" depends="init">

        <delete dir="${bin.dir}"/>

        <mkdir dir="${bin.dir}"/>

        <!--编译源程序-->

        <javac srcdir="${src.dir}" destdir="${bin.dir}" target="1.5">

            <classpath refid="master-classpath"/>

        </javac>

        <!--复制图标目录-->

        <mkdir dir="${bin.dir}/image"/>

        <copy todir="${bin.dir}/image">

            <fileset dir="image"/>

        </copy>

    </target>

    <!-- 打包 -->

    <target name="pack" depends="compile">

        <!-- bin目录压缩成JAR包 -->

        <delete dir="${dist.dir}"/>

        <mkdir dir="${dist.dir}"/>

        <jar basedir="${bin.dir}" destfile="${dist.dir}/struts1.2.jar" manifest="ant_manifes.txt">

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

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

        </jar>

        <!-- 复制用到的库 -->

        <mkdir dir="${dist.dir}/lib"/>

        <copy todir="${dist.dir}/lib">

            <fileset refid="project_lib"/>

        </copy>

        <!-- 复制本地化文件 -->

        <copy todir="${dist.dir}" file="${jsp.dir}"/>

    </target>

    <!-- 输出api文档 -->

    <target name="api_doc" depends="pack">

        <delete dir="${doc.dir}"/>

        <mkdir dir="${doc.dir}"/>

  <javadoc destdir="${doc.dir}" author="true" version="true" use="true" windowtitle="STRUTS1.2 API" useexternalfile="yes">

            <packageset dir="${src.dir}" defaultexcludes="yes" />

            <doctitle><![CDATA[<h1>STRUTS1.2 Project</h1>]]></doctitle>

            <bottom><![CDATA[<i>Document by Anhuixiao 2010.</i>]]></bottom>

        </javadoc>

    </target>

</project>

 

ant_manifes.txt内容:

Manifest-Version: 1.0
Main-Class: jface.dialog.wizard.WizardDialog1
Class-Path: ./WEB-INF/lib/antlr.jar ./WEB-INF/lib/commons-beanutils.jar ./WEB-INF/lib/commons-digester.jar ./WEB-INF/lib/commons-fileupload.jar ./WEB-INF/lib/commons-logging.jar ./WEB-INF/lib/commons-validator.jar ./WEB-INF/lib/jakarta-oro.jar ./WEB-INF/lib/mysql-connector-java-5.0.6-bin.jar ./WEB-INF/lib/struts.jar ./WEB-INF/lib/jasper-runtime.jar ./WEB-INF/lib/jsp-api.jar ./WEB-INF/lib/servlet-api.jar

 

你可能感兴趣的:(ant 学习笔记(Ant来打包))