欢迎光临
我们一直在努力

jakarta-ant的使用(java编译工具)-JSP教程,开发工具

建站超值云服务器,限时71元/月

一:介绍:

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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » jakarta-ant的使用(java编译工具)-JSP教程,开发工具
分享到: 更多 (0)