用Ant编译Scala
时间:2020-01-09 10:47:18 来源:igfitidea点击:
我们可以使用Apache Ant来编译Scala代码。在本文中,我将向我们展示如何做到这一点。这可能不是唯一的方法,但至少是一种方法。
这是完整的Ant脚本。它包含4个目标:
- prepare
- build
- run
- buid-run
这些目标的作用应该是不言而喻的。我不会详细解释该脚本。我们需要合理地了解Apache Ant才能理解它,但是我还认为该脚本将在很大程度上说明自己。
<?xml version="1.0"?> <project name="scala-tests" default="build-run" basedir="."> <!-- ======================================================== --> <!-- Initialization of all property settings --> <!-- ======================================================== --> <property file="local-environment.properties"/> <property name="name" value="tutorials"/> <target name="prepare"> <mkdir dir="build"/> </target> <macrodef name="scalac" > <attribute name="class" default="src/com/Hyman/scala/*.scala"/> <attribute name="output" default="build"/> <attribute name="sourcepath" default="c:\data\projects\scala\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:\data\projects\scala\build"/> <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"/> <-- you need 1 line (below) per scala source directory, including one for each package directory. --> <scalac class="src/com/Hyman/scala/*.scala"/> <scalac class="src/com/Hyman/scala/sub/*.scala"/> </target> <target name="run"> <!--<scala class="HelloWorld"/>--> <scala class="com.Hyman.scala.Main"/> </target> <target name="build-run"> <antcall target="build"/> <antcall target="run"/> </target> </project>