首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为scala配置ant

为scala配置ant
EN

Stack Overflow用户
提问于 2011-01-12 05:31:39
回答 1查看 12K关注 0票数 20

如何为scala安装antlib.xml以使ant正常工作?

现在,当我在包含scala任务的ant文件上运行build.xml时,我会遇到以下错误。

代码语言:javascript
复制
[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.

我已经把scala-2.8.1.final/lib/scala-compiler.jar写好了,但是我不知道把内容放在哪里。

下面是来自build.xml的相应的ant代码片段:

代码语言:javascript
复制
  <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文件中非常重要:

代码语言:javascript
复制
  <!-- 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目录。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-12 08:45:34

antlib.xml包含在Scala-编译器. The中。你得把它放进你的类路径。要定义scalacant任务,请将以下定义放入ant构建文件(这是http://www.scala-lang.org/node/98格式):

代码语言:javascript
复制
<target name="init">
  <property
    name="scala-library.jar"
    value="${scala.home}/lib/scala-library.jar"
     />
  <path id="build.classpath">
    <pathelement location="${scala-library.jar}"   />
    <!--<pathelement location="${your.path}"   />-->
    <pathelement location="${build.dir}"   />
  </path>
  <taskdef resource="scala/tools/ant/antlib.xml">
    <classpath>
      <pathelement location="${scala.home}/lib/scala-compiler.jar"   />
      <!-- NEW: For scala 2.10.2 you need scala-reflect: -->
      <pathelement location="${scala.home}/lib/scala-reflect.jar"   />
      <pathelement location="${scala-library.jar}"   />
    </classpath>
  </taskdef>
</target>

若要使用scalac任务,请将属性depends="init"添加到任务中。

代码语言:javascript
复制
<target name="compile" depends="init">
  <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>

希望你能帮上忙。

票数 20
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4665635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档