Reputation: 2874
I have this code (scala 2.9.1):
package pl.koziolekweb.scala.dsi
import scala.tools.nsc.interpreter.{ IMain, Results }
trait Eval {
def eval(expresion: String): Option[Any] = {
val interpreter = new IMain {
override protected def parentClassLoader: ClassLoader = App.getClass.getClassLoader
}
val res = new ResultSet
interpreter.beQuietDuring {
interpreter.bind("res", res.getClass.getCanonicalName, res)
interpreter.interpret("res.value = " + expresion)
} match {
case Results.Success => Option(res.value)
case _ => None;
}
}
}
object App extends Eval {
def main(args: Array[String]) {
{ eval(args(0)) } match {
case None => println("nie bangla")
case Some(x) => println(x)
}
}
}
class ResultSet {
var value : Any = null
}
when I compile it (maven)and run just call:
scala pl.koziolekweb.scala.dsi.App 1+1
program works fine (print 2). But after pack all of class files to jar and try to run
scala myapp.jar 1+1
i get
<console>:5: error: not found: value pl
var value: pl.koziolekweb.scala.dsi.ResultSet = _
^
<console>:6: error: not found: value pl
def set(x: Any) = value = x.asInstanceOf[pl.koziolekweb.scala.dsi.ResultSet]
^
<console>:7: error: not found: value res
res.value = 1+1
^
nie bangla
Why? any suggestions?
//edit:
I find reason. interpreter doesn't have myapp.jar
in classpath. How to load that jar to IMain?
Upvotes: 0
Views: 184
Reputation: 36229
Since your username is Koziolek
, and the failing identifier is pl.koziolekweb.scala.dsi.ResultSet
, it has to be something in your responsibility.
I don't see an import for ResultSet
, so I guess that pl.koziolekweb.scala.dsi is the package of App and Eval too. But I don't see a package-declaration.
But you call it with
scala my.pack.App 1+1
Is this a simplification for us? But it is in contradiction to the errormessage, so it's not a simplification, but a source of confusion.
Upvotes: 1