configure ant for scala

后端 未结 1 1050
执念已碎
执念已碎 2020-12-14 02:49

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

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

相关标签:
1条回答
  • 2020-12-14 03:05

    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>
    

    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.

    0 讨论(0)
提交回复
热议问题