以《Enterprise javaBean3.0》书的ex04_1例子说明ant的使用

 

Ant 使用说明

 

以《Enterprise javaBean3.0》书的ex04_1例子来说明:

<?xml version="1.0"?>

<!-- ======================================================================= -->

<!-- JBoss build file                                                       -->

<!-- ======================================================================= -->

<project name="ex04_1" default="ejbjar" basedir=".">  --name:指定项目名 

--default:指定运行build.xml时默认的target是哪一个,这里指定的是ejbjar

--basedir:已build.xml所在的路径为相对路径,指定basedir路径

  <property environment="env"/> --获取环境变量

  <property name="src.dir" value="${basedir}/src/main"/>--指定java代码路径

  <property name="src.resources" value="${basedir}/src/resources"/>--指定项目配置文件路径

  <property name="jboss.home" value="${env.JBOSS_HOME}"/>--根据环境变量指定jboss_home

  <property name="build.dir" value="${basedir}/build"/>--指定build.xml编译产生文件(jarwarear)的路径

  <property name="build.classes.dir" value="${build.dir}/classes"/>--指定java文件编译的class文件的路径

  <!-- Build classpath -->

  <path id="classpath"> --指定classpathjar以及相关的配置文件)

        <fileset dir="${jboss.home}/server/default/lib">

            <include name="*.jar"/>

        </fileset>

        <fileset dir="${jboss.home}/server/ejbstudy/deploy/ejb3.deployer">

            <include name="*.jar"/>

        </fileset>

        <fileset dir="${jboss.home}/server/ejbstudy/deploy/jboss-aop-jdk50.deployer">

            <include name="*.jar"/>

        </fileset>

        <fileset dir="${jboss.home}/lib">

            <include name="*.jar"/>

        </fileset>

                   <pathelement location="${build.classes.dir}"/>--run.client运行时需要依赖class

                   <!-- So that we can get jndi.properties for InitialContext and log4j.xml file -->

                   <pathelement location="${basedir}/client-config"/>--run.client运行时需要依赖的相关配置文件

  </path>

 <property name="build.classpath" refid="classpath"/>

  <!-- =================================================================== -->

  <!-- Prepares the build directory                                        -->

  <!-- =================================================================== -->

  <target name="prepare" >  --编译之前的准备(创建相关目录)

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

    <mkdir dir="${build.classes.dir}"/>

  </target>

  <!-- =================================================================== -->

  <!-- Compiles the source code                                            -->

  <!-- =================================================================== -->

  <target name="compile" depends="prepare"> --编译java源代码,depends指定编译执行前先执行prepare

    <javac srcdir="${src.dir}"  --指定java的源代码

           destdir="${build.classes.dir}"指定编译后class的存放路径

           debug="on"  --编译的文件是否支持debug调试

           deprecation="on"

           optimize="off"

           includes="**">

            <classpath refid="classpath"/>  --编译java源代码所依赖的classpath

    </javac>

  </target>

  <target name="ejbjar" depends="compile">  --编译ejbjar包,depends指定compile,则表示编译ejbjar之前先执行preparecompile

    <jar jarfile="build/titan.jar">  --生成的jar文件

      <fileset dir="${build.classes.dir}"> --指定生成的titan.jar包所包含的class文件

                 <include name="com/titan/domain/*.class"/>

                 <include name="com/titan/travelagent/*.class"/>

      </fileset>

      <fileset dir="${src.resources}/"> --指定生成的titan.jar包所包含的配置文件

          <include name="META-INF/persistence.xml"/>

      </fileset>

     </jar>

     <copy file="build/titan.jar" todir="${jboss.home}/server/ejbstudy/deploy"/>--拷贝titan.jar包到指定的jboss

</target>

  <target name="run.client" depends="ejbjar"> --运行Client

    <java classname="com.titan.clients.Client" fork="yes" dir=".">

      <classpath refid="classpath"/>

    </java>

  </target>

     <!-- =================================================================== -->

  <!-- Cleans up generated stuff                                           -->

  <!-- =================================================================== -->

  <target name="clean.db">   --清除数据库

    <delete dir="${jboss.home}/server/default/data/hypersonic"/>

  </target>

  <target name="clean">--清除目录

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

    <delete file="${jboss.home}/server/default/deploy/titan.jar"/>

  </target>

</project>

 

  Eclipseant中查看,蓝色的ejbjar为默认的target


执行run.client的结果


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值