<project name="jpa_acc_option1" default="build" basedir=".">
    <description>
        A simple build script.
        Since the example demonstrates two different way of packaging, 
        there are two build targets build-app1 and build-app2. The target
        called build depends on these two targets.
    </description>
  <!-- set global properties for this build -->
  <!-- change glassfish.home to point to appropriate location -->
  <property name="glassfish.home" location="/home/ss141213/ROOT/WS/gf/publish/glassfish"/>
  <property name="build" location="build"/>
  <property name="appname1" value="jpa_acc_option1"/>
  <property name="appname2" value="jpa_acc_option2"/>

  <target name="init">
    <!-- Create the build directory structure -->
    <mkdir dir="${build}/entities/META-INF"/>
    <mkdir dir="${build}/lib"/>
    <mkdir dir="${build}/appclient"/>
  </target>

  <target name="build-entities" depends="init" 
        description="compile the entity beans and prepare a PU jar file." >
    <javac classpath="${glassfish.home}/lib/javaee.jar" 
           srcdir="entities/src" 
           destdir="${build}/entities"/>
    <copy file="entities/persistence.xml" todir="${build}/entities/META-INF"/>
    <jar destfile="${build}/entities.jar" basedir="${build}/entities"/>
  </target>

  <target name="build-appclient" depends="build-entities"
        description="compile the appclient classes and prepare a jar file">
    <javac srcdir="appclient/src"
           destdir="${build}/appclient">
      <classpath>
        <pathelement location="${glassfish.home}/lib/javaee.jar"/>
        <pathelement location="${build}/entities.jar"/>
      </classpath>
    </javac>
    <jar destfile="${build}/appclient.jar" basedir="${build}/appclient"
         manifest="appclient/manifest.mf"/>
  </target>

  <!-- Build using option #1, where we package everything as one ear file-->
  <target name="build-app1" depends="build-appclient" 
          description="build the application">
    <copy file="${build}/entities.jar" todir="${build}/lib"/>
    <jar destfile="${build}/${appname1}.ear" basedir="${build}"
         includes="lib/*.jar appclient.jar"/>
  </target>

  <!-- Build using option #2, where we package everything as one jar file-->
  <target name="build-app2" depends="build-appclient" 
          description="build the application">
    <jar destfile="${build}/${appname2}.jar" basedir="${build}/appclient"
         manifest="appclient/manifest.mf"/>
    <jar destfile="${build}/${appname2}.jar" basedir="${build}/entities"
         update="yes"/>
  </target>

  <target name="build" description="build both app1 and app2" 
          depends="build-app1, build-app2" >
  </target>

  <target name="clean" description="clean up" >
    <delete dir="${build}"/>
  </target>

  <!-- The following targets are Sun Java System App Server specific.
       Since the example demonstrates two different way of packaging, 
       the targets have been suffixed with app1 and app2. The targets
       deploy, undeploy and verify deploys, undeploys and verifies both
       the applications. -->

  <target name="verify-app1" depends="build-app1" 
          description="verify compliance of the app against Java EE spec">
    <exec executable="${glassfish.home}/bin/verifier" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="-p -d ${build} ${build}/${appname1}.ear"/>
    </exec>
  </target>

  <target name="verify-app2" depends="build-app2" 
          description="verify compliance of the app against Java EE spec">
    <exec executable="${glassfish.home}/bin/verifier" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="-p -d ${build} ${build}/${appname2}.jar"/>
    </exec>
  </target>

  <target name="verify" description="verify both app1 and app2" 
          depends="verify-app1, verify-app2" >
  </target>

  <target name="deploy-app1" depends="build-app1"
          description="deploy to Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="deploy --user admin --passwordfile .adminpassword.txt --createtables ${build}/${appname1}.ear"/>
    </exec>
  </target>

  <target name="deploy-app2" depends="build-app2"
          description="deploy to Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="deploy --user admin --passwordfile .adminpassword.txt --createtables ${build}/${appname2}.jar"/>
    </exec>
  </target>

  <target name="deploy" description="deploy both app1 and app2" 
          depends="deploy-app1, deploy-app2" >
  </target>

  <target name="undeploy-app1" 
          description="undeploy from Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="undeploy --user admin --passwordfile .adminpassword.txt ${appname1}"/>
    </exec>
  </target>

  <target name="undeploy-app2" 
          description="undeploy from Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="undeploy --user admin --passwordfile .adminpassword.txt ${appname2}"/>
    </exec>
  </target>

  <target name="undeploy" description="undeploy both app1 and app2" 
          depends="undeploy-app1, undeploy-app2" >
  </target>
</project>
