2011-01-12 7 views
19

antを得るためにscala用のantlib.xmlをインストールするにはどうすればよいですか?スカラー用に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. 

私はscala-2.8.1.final/lib/scala-compiler.jarをunjarredしているが、私は内容をどこに置くか分かりません。

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

次のコードは、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のから対応する蟻コードスニペットです

私の問題は、$SCALA_HOMEという環境変数(${env.SCALA_HOME})が間違っている(/usr/local/scala-2.8.1.final/ではなく、1レベルが深すぎる:/usr/local/scala-2.8.1.final/bin/)、libディレクトリが見つかりませんでした。

+0

おそらく、関連するantコードスニペットを投稿する必要があります。おそらく、build.xmlにscalacのtypedefがありません。 – Raghuram

答えて

20

antlib.xmlは、scala-compiler.jarに含まれています。それをクラスパスに入れなければなりません。例えば、scalacタスクを使用して、あなたのタスクに属性depends="init"を追加するには

<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 Antタスクを定義するには、Antビルドファイル(これはフォームhttp://www.scala-lang.org/node/98を取られる)に次の定義を置きます

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

私はこれが役に立ちます。

+5

scala-compiler.jar行の前にこれを追加しなければなりませんでした。 ' ' (Scala 2.10 RC2の使用)。その前に私はこのエラーが発生しました: 'class scala.tools.ant.FastScalacに必要なクラスが見つかりません:scala/reflect/internal/settings/MutableSettings classloaderを使用するSettingValue AntClassLoader' –

+1

BREWを使用してscalaをインストールすると、/lib/to/libexec/lib /に変更する必要があります。 –

関連する問題