配置斯卡拉蚂蚁 [英] configure ant for scala

查看:189
本文介绍了配置斯卡拉蚂蚁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何安装antlib.xml斯卡拉让蚂蚁的工作?

How do I install the antlib.xml for scala to get ant working?

现在我遇到以下错误,当我运行蚂蚁在包含Scala的任务的build.xml文件。

Right now I encounter the following error when I run ant on a build.xml file that contains scala tasks.

[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 ,但我不知道往哪里放的内容。

I have unjarred the scala-2.8.1.final/lib/scala-compiler.jar but I don't know where to put the contents.

下面是从build.xml文件对应的蚂蚁code片断:

Here is the corresponding ant code snippet from the 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>

以下code是重要的是在你的build.xml文件:

The following code is important to have in your build.xml file:

  <!-- 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 /本地/ scala-2.8.1.final / ,因此, LIB 目录无法找到。

My problem was that the $SCALA_HOME environment variable (${env.SCALA_HOME}) was pointing to the wrong place (one level too deep: /usr/local/scala-2.8.1.final/bin/ rather than just /usr/local/scala-2.8.1.final/, and therefore the lib directory could not be found.

推荐答案

该antlib.xml包含在斯卡拉-compiler.jar。你必须把它放到你的类路径中。要定义 scalac Ant任务,把下面的定义到Ant构建文件(这是初步形成的 http://www.scala-lang.org/node/98 ):

The antlib.xml is contained in the scala-compiler.jar. You have to put it into your classpath. To define the scalacant task, put the following definition into your ant build file (this is taken form http://www.scala-lang.org/node/98):

<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 任务,添加属性取决于=初始化来你的任务,如:

To use the scalac task, add the attribute depends="init" to your task, e.g.

<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>

我希望有所帮助。

I hope, that helps.

这篇关于配置斯卡拉蚂蚁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆