眾所周知,,ant是java部署開發(fā)工具,以前看過的一些使用方法都是有ant安裝文件的,,今天看到rickard oberg(Jboss 構架師)使用的 ant包使用方法,,特地拿出來分享一下,。
1 開發(fā)目錄結構:
src目錄:
main目錄:存放可執(zhí)行文件,注意,,文件全部按包結構位置,,放置到位
lib目錄:存放jar文件,例如rmi應用中經(jīng)常用到的:Dynaserver.jar(簡易web服務器);jndi.jar(jndi庫);rmiregistry.jar(rmi庫);providerutil.jar(jndi庫)
resources:存放一個配置文件,例如:jndi.properties,;system.properties,;最后一起放到包里
etc目錄:存放配置文件。例如manifest.mf,,主要存放jar文件的配置文件
build目錄:存放build.xml,build.bat
lib目錄:存放ant包,,例如:jaxp.jar;ant.jar,;parser.jar
dist目錄:結果包,,最后打好的包,存放在這里
build目錄:用來存放,,為了打包而存在的中間代碼文件等
bin目錄:存放啟動用,,批處理文件,例如,,啟動服務器,,啟動客戶的批處理
2 build.xml結構
<?xml version="1.0"?>
<!-- ======================================================================= --> <!-- HelloApplet build file --> <!-- ======================================================================= -->
<project name="HelloApplet" default="main" basedir="../.."> <path id="project.class.path"> <fileset dir="${basedir}/lib"/> <fileset dir="${basedir}/src/lib"/> <pathelement location="${basedir}/build/classes" /> </path> <target name="init"> <property name="Name" value="HelloApplet"/> <property name="name" value="helloapplet"/> <property name="version" value="1.0"/>
<property name="lib.dir" value="${basedir}/lib"/> <property name="src.dir" value="${basedir}/src"/> <property name="build.dir" value="${basedir}/build"/> <property name="dist.dir" value="${basedir}/dist"/>
</target>
<!-- =================================================================== --> <!-- Prepares the directories --> <!-- =================================================================== --> <target name="prepare" depends="init">
<mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}/classes"/> <mkdir dir="${build.dir}/lib"/> <mkdir dir="${build.dir}/bin"/>
<mkdir dir="${dist.dir}"/> <mkdir dir="${dist.dir}/lib"/> <mkdir dir="${dist.dir}/src"/> </target> <!-- =================================================================== --> <!-- Compiles the source code --> <!-- =================================================================== --> <target name="compile" depends="prepare"> <javac srcdir="${src.dir}/main" destdir="${build.dir}/classes" debug="on" deprecation="off" optimize="off"> <classpath refid="project.class.path" /> </javac> <rmic base="${build.dir}/classes" classname="masteringrmi.helloapplet.server.HelloWorldImpl" stubVersion="1.2"> <classpath refid="project.class.path" /> </rmic> </target>
<!-- =================================================================== --> <!-- Creates the jar archives --> <!-- =================================================================== --> <target name="jar" depends="compile"> <copy todir="${build.dir}/classes"> <fileset dir="${src.dir}/resources"/> </copy>
<jar jarfile="${build.dir}/bin/server.jar" basedir="${build.dir}/classes" manifest="${src.dir}/etc/server.mf" /> </target> <!-- =================================================================== --> <!-- Creates the binary structure --> <!-- =================================================================== --> <target name="main" depends="jar"> <copy todir="${dist.dir}/lib"> <fileset dir="${src.dir}/lib"/> </copy> </target>
關于以上ant文件的含義,可以參考網(wǎng)上的一些資料
3build.bat內(nèi)容
@echo off rem ----- Verify and Set Required Environment Variables -----------------------
if not "%JAVA_HOME%" == "" goto gotJavaHome echo You must set JAVA_HOME to point at your Java Development Kit distribution goto cleanup
:gotJavaHome
set _CP_=..\..\lib\ant.jar set _CP_=%_CP_%;..\..\lib\parser.jar set _CP_=%_CP_%;..\..\lib\jaxp.jar
%JAVA_HOME%\bin\java.exe -classpath "%JAVA_HOME%\lib\tools.jar;%_CP_%;%CLASSPATH%" org.apache.tools.ant.Main %1 %2 %3 %4 %5
:cleanup
4system.properties/jndi.properties
都是運行時配置文件,,其中jndi.properties會自動加載,,內(nèi)容如:
java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory java.naming.provider.url=rmi://localhost
system.properties需通過程序調(diào)用
System.getProperties().load( Thread.currentThread(). getContextClassLoader(). getResourceAsStream("system.properties"));
一般內(nèi)容如下:
java.rmi.server.hostname=localhost java.rmi.server.codebase=http://localhost:8080/
|