如何爲scala安裝antlib.xml以獲得ant工作?爲scala配置ant
現在我在包含scala任務的build.xml文件上運行ant
時遇到以下錯誤。
[taskdef] Could not load definitions from resource scala/tools/ant/antlib.xml. It could not be found.
/scalala/scalala-read-only/scalala/build.xml:36: Problem: failed to create task or type scalac
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
我已經unjarred的scala-2.8.1.final/lib/scala-compiler.jar
,但我不知道往哪裏放的內容。
下面是從build.xml文件對應螞蟻的代碼片段:
<target name="compile" depends="">
<mkdir dir="${build.dir}"/>
<scalac srcdir="${src.dir}" destdir="${build.dir}"
classpathref="project.classpath" force="changed">
<!-- addparams="-Yclosure-elim -optimise" -->
<include name="**/*.scala"/>
</scalac>
</target>
回答
下面的代碼是很重要的在你的build.xml文件:
<!-- Define project CLASSPATH. -->
<path id="project.classpath">
<pathelement location="${build.dir}" />
<fileset dir="${env.SCALA_HOME}/lib/"> <include name="*.jar" /> </fileset>
<fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset>
</path>
<!-- Define scala compiler, scaladoc, etc command -->
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${env.SCALA_HOME}/lib/scala-compiler.jar" />
<pathelement location="${env.SCALA_HOME}/lib/scala-library.jar" />
</classpath>
</taskdef>
我的問題是$SCALA_HOME
環境變量(${env.SCALA_HOME}
)指向錯誤(一個級別太深:/usr/local/scala-2.8.1.final/bin/
而不僅僅是/usr/local/scala-2.8.1.final/
,因此找不到lib
目錄。
也許你應該發佈相關的ant代碼片段。也許你不具備scalac一個typedef在你的build.xml – Raghuram 2011-01-12 05:35:42