Compile Scala Program using Ant Library

http://jakarta.apache.org/ant/. Ant allows the developer to automate the repeated process involved in the development of Java/Scala application. Developers can easily write the script to automate the build process like compilation, archiving and deployment.

 

<?xml version="1.0"?>
<project name="scala-sample" default="build-run" basedir=".">
<!-- ======================================================== -->
<!-- Initialization of all property settings                  -->
<!-- ======================================================== -->
  <property file="local-environment.properties"/>
  <property name="name" value="Samples"/>
  <target name="prepare">
       <mkdir dir="classes"/>
  </target>
  <macrodef name="scalac" >
   <attribute name="class" default="src/com/kodehelp/scala/*.scala"/>
   <attribute name="output" default="classes"/>
   <attribute name="sourcepath" default="c:\workspace\ScalaExamples\src"/>
   <sequential>
       <exec executable="${scala-home}\bin\scalac.bat">
           <arg value="-d"/>
           <arg value="@{output}"/>
           <arg value="-sourcepath"/>
           <arg value="@{sourcepath}"/>
           <arg value="@{class}"/>
       </exec>
   </sequential>
  </macrodef>
  <macrodef name="scala">
   <attribute name="class" />
   <attribute name="classpath" default="c:\workspace\ScalaExamples\classes"/>
   <sequential>
       <exec executable="${scala-home}\bin\scala.bat">
         <arg value="-classpath"/>
         <arg value="@{classpath}"/>
         <arg value="@{class}"/>
         <!--<arg value="-classpath build "/>-->
         <!--<arg value="@{class}"/>-->
       </exec>
   </sequential>
  </macrodef>

  <target name="build" >
   <antcall target="prepare"/>
   <scalac class="src/com/kodehelp/scala/*.scala"/>
  </target>

   <target name="run">
    <scala class="ScalaHelloWorld"/>
   </target>

   <target name="build-run">
       <antcall target="build"/>
       <antcall target="run"/>
   </target>

</project>

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.