jakarta-ant的使用(java编译工具)
发布日期:2021-08-26 18:18:21 浏览次数:64 分类:技术文章

本文共 6937 字,大约阅读时间需要 23 分钟。

一:介绍:
ant 是jakarta的一个编译工具,如果你了解linux/Unix下的makefile你就很容易理解ant的用途了。ant最适合你使用UltraEdit(EditPlus)写java程序,然后你使用ant去编译,同时javadoc ,生成一个jar,war,实现文件的copy都可以在build.xml通过不同的tager去实现,还是很方便的一个东东强烈推荐是使用。
二:下载
    你可以从下面的地址下载到ant,目前版本:1.41
    http://jakarta.apache.org/builds/jakarta-ant/release/v1.4.1/bin/
    
三:安装
a:)Windows
    1:解压你下载的文件,会有一个jakarta-ant(版本号的)目录产生,把他改名为ant
    2:copy ant 目录到你需要的位置。
    3:在环境变量中添加:ANT_HOME=ant的安装目录,path中加$ANT_HOME$\in;注意你同时必须已经安装了jdk,并添加了JAVA_HOME的环境变量,同时早path中加了$JAVA_HOME$\in;
b:)Linux/Unix
    1:解压你下载的文件,会有一个jakarta-ant(版本号的)目录产生,把他改名为ant
    2:copy ant 目录到你需要的位置。
    3:在环境变量中添加:ANT_HOME=ant的安装目录,path中加$ANT_HOME$\in;注意你同时必须已经安装了jdk,并添加了JAVA_HOME的环境变量,同时早path中加了$JAVA_HOME$\in;实现修改环境变量你需要修改.bash_profile文件。
    如下
    ANT_HOME=/usr/local/ant
    JAVA_HOME=/usr/local/jdk
    PATH=$PATH:$HOME/bin:/usr/local/ant/bin:/usr/local/jdk/bin
    export PATH ANT_HOME JAVA_HOME
四:编写build.xml
build.xml相当Linux下的makefile,具体的实现都在build.xml中实现。
我给给例子说明一下。
build.xml
================================================================
<project name="bingo" default="build" basedir="../.." >
    <!--basedir设定工作目录-->
  <property name="version" value="1.0"/>
  <!-- The base directory relative to which most targets are built -->
  <property name="base" value="."/>
 
  <!-- The directory where source files are stored. -->
  <property name="java.source.dir" value="bingo/src"/>
  <!--代码保存路径-->
  <!-- Destination for compiled files -->
  <property name="javac.dest" value="bingo/classes"/>
    <!--class保存路径-->
  <!-- Destination for generated jar files -->
  <property name="jar.dest" value="bingo/jar"/>
  <!--jar文件保存路径-->
  <!-- Destination for documentation files generated or not -->
  <property name="docs" value="bingo/docs"/>
  <!--javadoc文件保存路径-->
  <!-- Destination for javadoc generated files -->
  <property name="javadoc.dest" value="bingo/docs"/>
  <!-- The stem where most log4j source code is located. -->
  <property name="stem" value="com/bingo"/>
  <property name="base-files" value="include"/>
  
  <!-- Original manifest.mf file before filtering. -->
  <property name="manifest.src" value="bingo/build/manifest.mf"/>
      
  <!-- Some targets needs a more precise stem. -->
  <property name="BSTEM" value="${java.source.dir}/${stem}"/>
  
   <property name="tomcat.dir" value="c:/Apache/Tomcat"/>
  
  <property name="webapp.dir" value="${tomcat.dir}/webapps/ROOT/WEB-INF/classes"/>
  
  <!--List all Package used in this project    -->
  <property name="PackageList" value="
               com.bingo,
             com.bingo.database,
             com.bingo.dbocw,
             com.bingo.util,
             com.bingo.taglibs.jndi,
             com.bingo.finance.database,
             com.bingo.finance.entity,
             com.bingo.finance.manager"
  />
  <!--你的project中所有的包-->
  <!-- List all jar or file used in this project -->
  <property name="classpath" value="${classpath};
                      ${base-files}/tomcat/servlet.jar;
                      ${base-files}/tomcat/webserver.jar;
                      ${base-files}/log4j/log4j.jar;
                      ${base-files}/log4j/log4j-core.jar"
                      
      />
  <!--你需要用到的包-->
  <target name="init">
    <tstamp />
  </target>
  <target name="build" depends="init">
    <echo>
        Building... 
    </echo>
    <mkdir dir="${javac.dest}" />
    <javac srcdir="${java.source.dir}"
       destdir="${javac.dest}"
       classpath="${classpath}"
       debug="on"/>            
       
  </target>
  <!-- ================================================================= -->
  <!-- Copy  class files to tomcat dir.                                      -->
  <!-- ================================================================= -->
   <target name="copy" depends="build">
    <copy todir="${webapp.dir}/com/bingo">
        <fileset dir="${javac.dest}/com/bingo">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/util">
        <fileset dir="${javac.dest}/com/bingo/util">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/database">
        <fileset dir="${javac.dest}/com/bingo/database">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/dbocw">
        <fileset dir="${javac.dest}/com/bingo/dbocw">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/finance/database">
        <fileset dir="${javac.dest}/com/bingo/finance/database">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/finance/entity">
        <fileset dir="${javac.dest}/com/bingo/finance/entity">
            <include name="*.class"/>
        </fileset>
    </copy>    
    <copy todir="${webapp.dir}/com/bingo/finance/manager">
        <fileset dir="${javac.dest}/com/bingo/finance/manager">
            <include name="*.class"/>
        </fileset>
    </copy>    
  </target>
  <!-- ================================================================= -->
  <!-- Remove all generated (compiled) class files.                      -->
  <!-- ================================================================= -->
  <target name="clean" depends="init">
    <delete dir="${javac.dest}/" />
  </target>
  
  <!-- ================================================================= -->
  <!-- Remove all backup  files.                                         -->
  <!-- ================================================================= -->
  <target name="delete" depends="init">
    <delete >
        <fileset dir="${java.source.dir}/com/bingo">
            <include name="*.bak"/>
        </fileset>
    </delete>
    <delete >
        <fileset dir="${java.source.dir}/com/bingo/util">
            <include name="*.bak"/>
        </fileset>
    </delete>
    <delete >
        <fileset dir="${java.source.dir}/com/bingo/database">
            <include name="*.bak"/>
        </fileset>
    </delete>
    <delete >
        <fileset dir="${java.source.dir}/com/bingo/finance/database">
            <include name="*.bak"/>
        </fileset>
    </delete>
    <delete >
        <fileset dir="${java.source.dir}/com/bingo/finance/entity">
            <include name="*.bak"/>
        </fileset>
    </delete>
    <delete >
        <fileset dir="${java.source.dir}/com/bingo/finance/manager">
            <include name="*.bak"/>
        </fileset>
    </delete>
  </target>
  
  <!-- ================================================================= -->
  <!-- Remove the temporary manifest file, actual work is done in the    -->
  <!-- dependencies.                                                     -->
  <!-- ================================================================= -->  
  
  <target name="prejar" depends="build">
    <mkdir dir="${jar.dest}"/>    
    <filter token="version" value="${version}" />
    <copy file="${manifest.src}" tofile="${jar.dest}/manifest.mf" 
          filtering="true"/>
  </target>
  
  <!-- ================================================================= -->
  <!-- This target Create    bingo.jar                                     -->
  <!-- ================================================================= -->
  <target name="jar" depends="prejar">
    <delete file="${jar.dest}/bingo.jar"/>
    <jar jarfile="${jar.dest}/bingo.jar" basedir="${javac.dest}"
        manifest="${jar.dest}/manifest.mf"    
    />
  </target>
  
  <!-- ================================================================= -->
  <!-- This target builds the javadoc files.                             -->
  <!-- ================================================================= -->
  <target name="javadoc" depends="build,init">
    <mkdir dir="${javadoc.dest}" />
    <javadoc sourcepath="${java.source.dir}" 
               destdir="${javadoc.dest}" 
               classpath="${classpath}"
               packagenames="${PackageList}"
               version="true"
               protected="true"
              author="true"
               use="true"           
               windowtitle="Bingo Free Java Code Version ${version}" 
               header="Bingo Free Java Code${version}"
     />            
  </target>
</project>

转载于:https://www.cnblogs.com/licheng/archive/2008/11/04/1326342.html

转载地址:https://blog.csdn.net/weixin_33894640/article/details/92631972 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:1.介绍多线程
下一篇:开源 java CMS - FreeCMS2.8 数据对象 infoContent

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年03月22日 01时32分33秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

java接口的理解_Java接口的理解 - rabbit_mom的个人空间 - OSCHINA - 中文开源技术交流社区... 2019-04-21
java重用名快捷键_Eclipse 最常用的 10 组快捷键,个个牛逼! 2019-04-21
java中类加载根路径_java中获取类加载路径和项目根路径的5种方法 2019-04-21
Java套接字传文件_Java通过套接字传输多个文件 2019-04-21
递归字符串逆序 java_在Java中使用递归反转字符串 2019-04-21
java推送功能实现原理图_IOS 基于APNS消息推送原理与实现(JAVA后台) - 图文 2019-04-21
java streamencoder_[求助]关于apcche与tomcat 2019-04-21
golang mongodb mysql_分享一个golang+mongodb+vuejs开发的博客程序 gocms 2019-04-21
hive java insert_hive表insert报错 2019-04-21
java 调试dll jna_Java调用dll的实现,JNA框架 | 学步园 2019-04-21
ios php上传视频文件_IOS上传图片 PHP服务器接收并上传 2019-04-21
php redis zrevrange,Redis Zrevrange 命令 2019-04-21
php利用word模板导出excel文件,php生成导出word doc和excel文件实例 2019-04-21
java 边缓存边播放,java动态缓存技术:WEB缓存应用 2019-04-21
php云盘匿名,PHP7之匿名类 2019-04-21
matlab数据大小不兼容,MATLAB无法执行赋值,因为左侧的索引与右侧的大小不兼容。 求解... 2019-04-21
editor.md使用php,editor.md 配置参数和使用方法 2019-04-21
python mod,mod_python的安装 2019-04-21
python分析彩票数据,这波太炸了!Python脚本可视化居然可以这么玩 2019-04-21
简单的mysql重置root密码,重置mysql的root密码最简单的方法 2019-04-21