<?xml version="1.0"?>

<!-- ======================================================================= -->
<!-- JBoss build file                                                       -->
<!-- ======================================================================= -->

<project name="JBoss" default="ejbjar" basedir=".">

   <property environment="env"/>
   <property name="src.dir" value="${basedir}/src"/>
   <property name="jboss.home" value="${env.JBOSS_HOME}"/>   <property name="jboss.server.config" value="all"/>
   <property name="build.dir" value="${basedir}/build"/>
   <property name="build.classes.dir" value="${build.dir}/classes"/>

   <!-- Build classpath -->
   <path id="classpath">
      <!-- So that we can get jndi.properties for InitialContext -->
      <pathelement location="${basedir}"/>
      <fileset dir="${jboss.home}/lib">
         <include name="**/*.jar"/>
      </fileset>
      <fileset dir="${jboss.home}/server/${jboss.server.config}/lib">
         <include name="**/*.jar"/>
      </fileset>
      <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/ejb3.deployer">
         <include name="*.jar"/>
      </fileset>
      <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/jboss-aop-jdk50.deployer">
         <include name="*.jar"/>
      </fileset>
      <pathelement location="${build.classes.dir}"/>
   </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">
      <javac srcdir="${src.dir}"
         destdir="${build.classes.dir}"
         debug="on"
         deprecation="on"
         optimize="off"
         includes="**">
         <classpath refid="classpath"/>
      </javac>
   </target>

   <target name="ejbjar" depends="compile">
      <jar jarfile="build/tutorial.jar">
         <fileset dir="${build.classes.dir}">
            <include name="**/*.class"/>
         </fileset>
      </jar>
      <copy file="build/tutorial.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
   </target>

   <target name="run" depends="ejbjar">
      <java classname="org.jboss.tutorial.stateless.client.Client" fork="yes" dir=".">
         <classpath refid="classpath"/>
      </java>
   </target>

   <!-- =================================================================== -->
   <!-- Cleans up generated stuff                                           -->
   <!-- =================================================================== -->
   <target name="clean.db">
      <delete dir="${jboss.home}/server/${jboss.server.config}/data/hypersonic"/>
   </target>

   <target name="clean">
      <delete dir="${build.dir}"/>
      <delete file="${jboss.home}/server/${jboss.server.config}/deploy/tutorial.jar"/>
   </target>


</project>

