Build ant script to build jars and zip files for scheduled Task.

In Oracle Identity Management for our implementation purpose, we write many schedules. But many times we want the only custom set of classes to register in the system, for that we always need to go and do changes in metadata plugin XML files and then registered the schedulers.

Here a small ant script that we can use to compile a set of custom classes, build Jar, and zip file of those custom classes which we need to register in our environment.


Please find below the folder structure.




  src = Contains all scheduled tasks java classes.
  build = All compile classes will be generated in this folder.
  lib = Jar file will be stored here.
  META-INF your custom scheduled task XML

Steps to be done before running the script.
  1. You need to create a tmp folder.
  2. Prepare your custom set of metadata and plugin XML like scheduledTask_Set1.xml and plugin_Set1.xml and put those XMLs in the tmp folder.
  3. The script will runtime pick that XMLs according to target which we'll be running.

build.xml

<project name="MyCustomScheduledTasks" basedir="." default="main">


 <property name="src.dir"     value="src"/>

 <property name="build.dir"   value="build"/>
 <property name="classes.dir" value="${build.dir}/classes"/>
 <property name="lib.dir" value="lib"/>
 <property name="meta-inf.dir" value="META-INF"/>
 <property name="tmp.dir" value="tmp"/>
 <property name="set1.dir" value="set1"/>
 <property name="set2.dir" value="set2"/>
<property file ="build.properties"/>

 <target name="clean">

  <delete dir="${build.dir}"/>
  <delete dir="${meta-inf.dir}"/>
  <delete dir="${lib.dir}"/>
  <delete file="plugin.xml"/>
 </target>

 <target name="compile">

  <mkdir dir="${classes.dir}"/>
  <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
 </target>

 <target name="set1" depends="compile">

  <mkdir dir="${lib.dir}" />
  <mkdir dir="${meta-inf.dir}" />
  <mkdir dir="${set1.dir}" />
  <jar destfile="${lib.dir}/${ant.project.name}.jar" basedir="${classes.dir}" incluedes="${set1.classes}">
  </jar>
  <copy file="${tmp.dir}/plugin_Set1.xml" tofile="plugin.xml" />
  <copy file="${tmp.dir}/ScheduledTasks_Set1.xml" tofile="${meta-inf.dir}/ScheduledTasks.xml" />
  <zip destfile="${set1.dir}/${ant.project.name}.zip" basedir=".">
   <include name="plugin.xml" />
   <include name="${meta-inf.dir}/ScheduledTasks.xml" />
   <include name="${lib.dir}/${ant.project.name}.jar" />
  </zip>
 </target>

 <target name="set2" depends="compile">

  <mkdir dir="${lib.dir}" />
  <mkdir dir="${meta-inf.dir}" />
  <mkdir dir="${set2.dir}" />
  <jar destfile="${lib.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="${set2.classes}" >
  </jar>
  <copy file="${tmp.dir}/plugin_Set2.xml" tofile="plugin.xml"/>
  <copy file="${tmp.dir}/ScheduledTasks_Set2.xml" tofile="${meta-inf.dir}/ScheduledTasks.xml"/>
  <zip destfile="${set1.dir}/${ant.project.name}.zip" basedir=".">
   <include  name="plugin.xml"/>
   <include name="${meta-inf.dir}/ScheduledTasks.xml"/>
   <include name="${lib.dir}/${ant.project.name}.jar"/>
  </zip>
 </target>

 <target name="main" depends="clean"/>


</project>

In build.properties file you have to mention the comma-separated set of custom classes.

build.properties looks like this,

set1.classes com/myTask/DisableUser.class,com/myTask/CreateUser.class

set2.classes com/myTask/EnableUser.class,com/myTask/UpdateUserParameters.class

I am still working on this script. If any suggestions then those are always welcome.


Happy Coding. 



No comments:

Post a Comment