Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call the scala interpreter in a Simple Build Tool project?

Tags:

my scala program is using the compiler interface from scala.tools.nsc.interpreter.IMain. When I am compiling with scalac, everything works as expected. But when I compile with sbt it still compiles, but on execution it throws the following error message in the call of the interpret-method from the IMain instance:

Failed to initialize compiler: object scala not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programatically, settings.usejavacp.value = true.

If I use settings.usejavacp.value = true on the IMain instance, I get the following exception:

java.lang.Error: typeConstructor inapplicable for <none>

My SBT project definition:

class Project(info: ProjectInfo) extends DefaultProject(info){
    val scalaSwing = "org.scala-lang" % "scala-swing" % "2.9.0"
    val scalaCompiler = "org.scala-lang" % "scala-compiler" % "2.9.0"
}

What's wrong here? And how can I use the interpreter in a Simple Build Tool Project?

I'm using Scala 2.9.0 and Simple Build Tool 0.7.7

like image 571
Felix Dietze Avatar asked Jun 11 '11 11:06

Felix Dietze


People also ask

How do I compile a Scala project?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.

What is sbt console?

SBT is tied to a specific project defined by a build. sbt file in a way that $ sbt console will load up the same REPL environment as $ scala but with the addition of all of the project code and dependencies defined in the build available for import. Also, it will use the version of Scala defined by build. sbt .


2 Answers

sbt console // Starts a Scala interpreter

Here is the new FAQ (the previous answer is obsolete)

http://www.scala-sbt.org/0.12.4/docs/faq.html

You can find also the FAQ for more recent versions.
Note that sbt console-quick loads the console without the dependencies.

like image 51
Mikaël Mayer Avatar answered Oct 01 '22 14:10

Mikaël Mayer


Take a look at the SBT wiki: http://www.scala-sbt.org/0.13/docs/Faq.html#How+do+I+use+the+Scala+interpreter+in+my+code%3F

There's an entry about getting the interpreter running.

like image 28
sorowd Avatar answered Oct 01 '22 15:10

sorowd