m.dr (70) [Avatar] Offline
#1
Hello All -
...
* Please note I am working on ScalaInSction but this is a general Scala command line question. Posted there as well but wanted to check here as well since that forum seems to be a little slow right now. *
...
I am trying to go through the chapters and had a few questions while using the command line. I am using it in a slightly different way than most of you are I think.

I am writing the code within Eclipse (Juno) and fix any errors there. I am compiling with Gradle.

But since Gradle does not have a REPL (that works) and also I am using the Scala 2.10 plugin, there seems to be no REPL in Eclipse either to try out code.

So I am left with running from the command line (Scala installed in Ubuntu).

When I am at the Scala prompt in the directory src/main/scala below which the classes / objects exist in com.scalainaction., my imports to get to a class from the command line does not work.

So I am in src/main/scala and from the cmd line I run scala. I import com.scalainaction. This should import all classes under it. However when I say execute:
val client = new MongoClientV2("127.0.0.1", 123)

I get an error saying MongoClientV2 cannot be found. I even tried going to directory where MongoClientV2 is located and imported it it still does not find it.

I have included example snipped below:
...
scala> import com.scalainaction
import com.scalainaction

scala> val client = new MongoClientV2("127.0.0.1", 123)
<console>:8: error: not found: type MongoClientV2
val client = new MongoClientV2("127.0.0.1", 123)
...
As you can see the import statement works.
Fails on MongoClientV2. Its there in com.scalainaction.

Any ideas why this is happening - and what I may need to be doing to run from the command line - which would be my Scala REPL.

Thank you for your help.
joshua.suereth (60) [Avatar] Offline
#2
Re: Scala from command line
Hey, sorry for the long delay in replying. Twofold answer:

(1) Eclipse has a "worksheet" feature that seems to be the replacement for a REPL inside it.
(2) When importing packages, import x.y makes "y" available for reference, but not the *members* of "y". SO,

import com.scalainaction
new scalainaction.MongoClientV2(....)


would work, *or*

import com.scalainaction._