2

With sbt everything is fine:

» sbt console
[info] Loading project definition from /repos/myrepo/project
[info] Set current project to bpavscan (in build file:/repos/myrepo/)
[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> import play.api.libs.json._
import play.api.libs.json._

scala> 

But if I do it with the scala tool:

» scala
Welcome to Scala version 2.11.6 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import play.api.libs.json._
<console>:7: error: not found: value play
       import play.api.libs.json._
              ^

scala>

I need to run a simple script, which I usually do with:

scala myscript.scala

But since now my script has a play dependency, I can not run it with scala anymore, since scala does not find play.

I need to either:

  1. Be able to load the play framework with the simple scala tool
  2. Be able to run a simple script with sbt: sbt run runs my project, which I do not want. I want to run a simple script (to try out some simple things)
blueFast
  • 41,341
  • 63
  • 198
  • 344
  • 1
    Because the Scala REPL has no clue as to what your dependencies are, while SBT is literally in charge of managing all your project dependencies. – Yuval Itzchakov Jun 14 '17 at 11:17
  • @YuvalItzchakov how can I run a simple script making use of the installed dependencies? Is there a `sbt runscript `? – blueFast Jun 14 '17 at 11:24
  • 1
    https://stackoverflow.com/questions/18812399/how-to-use-third-party-libraries-with-scala-repl – Yuval Itzchakov Jun 14 '17 at 11:25

1 Answers1

2

sbt console with load the same console/REPL as of scala but with additional loaded dependencies defined in build.sbt. So before loading the console, all the dependent libraries are added. And this is reason you could import play libraries while using sbt console.

On the other hand scala starts the console with the libraries inside scala-package of the system. Thus needs additional jars being included inside the package for importing. For the above case if play library jar was included in scala directory then import play.api.libs.json._ should have worked for scala console too.

Jonny Cundall
  • 2,552
  • 1
  • 21
  • 33
Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97