Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ToolBox Import Error

Tags:

scala

I'm getting the following error when compiling the following toy class:

package com.example

import scala.tools.reflect.ToolBox
import scala.reflect.runtime.{currentMirror => m}
object Hello {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

[info] Loading project definition from /Users/me/Temp/Bar/project
[info] Set current project to Bar (in build file:/Users/me/Temp/Bar/)
[info] Compiling 1 Scala source to /Users/me/Temp/Bar/target/scala-2.11/classes...
[error] /Users/me/Temp/Bar/src/main/scala/com/example/Hello.scala:3: object tools is not a member of package scala
[error] import scala.tools.reflect.ToolBox
[error]              ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

This is my build.sbt file:

name := """Bar"""

version := "1.0"

scalaVersion := "2.11.8"

// Change this to another test framework if you prefer                                                                                                                                                      
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4" % "test"
libraryDependencies += "org.scala-lang"     % "scala-reflect"   % "2.11.8"

// Uncomment to use Akka                                                                                                                                                                                    
//libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.11"  
like image 707
M.K. Avatar asked May 20 '16 20:05

M.K.


2 Answers

The following dependency fixed the issue:

libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.11.8"

Is this the best solution?

like image 99
M.K. Avatar answered Sep 28 '22 00:09

M.K.


The ToolBox class is part of the compiler, not the public reflection API.

like image 25
pedrofurla Avatar answered Sep 27 '22 22:09

pedrofurla