yalis
yalis

Reputation: 1518

Does scala have something similar to jython's standalone jar?

With jython's standalone jar you can do:

java -jar jython-standalone-2.5.3.jar

And the repl starts.

I'd like to do that with scala:

java -jar scala-standalone.jar 

This would put me into the scala repl.

Let me ask this another way. How do you invoke the scala repl using java.

java -cp <jars> <class-with-main-method>

In paticular, I don't want to use the scala cli or even have it installed.

Upvotes: 4

Views: 270

Answers (3)

0__
0__

Reputation: 67280

You could build one yourself if necessary. There is a recent blog post that shows you how to create a REPL. If you build that code with sbt and drop in the sbt-assembly plugin, you should get a standalone REPL via sbt assembly.

Upvotes: 2

Plasty Grove
Plasty Grove

Reputation: 2877

You can definitely do it through java -jar, but my guess is it won't be as easy as jython. For example, if you look at scala.bat (on windows) in the standard install of scala, you will see that is using some variant of the following command:

"java" -Xmx256M -Xms32M -Dscala.home="C:\PROGRA~2\scala\bin\.." -Denv.emacs=""
-Dscala.usejavacp=true  -cp "C:\PROGRA~2\scala\bin\..\lib\jline.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-actors.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-compiler.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-library.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-partest.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-reflect.jar;
C:\PROGRA~2\scala\bin\..\lib\scala-swing.jar;
C:\PROGRA~2\scala\bin\..\lib\scalacheck.jar;
C:\PROGRA~2\scala\bin\..\lib\scalap.jar" scala.tools.nsc.MainGenericRunner

All in one single line of course. I did a cd into the scala installation directory and then the bin folder and ran this command directly. It gave me a scala repl.

I'm guessing you can probably skip some of the jars (swing, actors etc), combine the rest into a single jar and get rid of some of the command line params and then kick it off using java -jar myscala.jar

PS: If you're trying to do something with android, beware it won't work. Because I've tried it before: Scala REPL in an Android app

:D

Upvotes: 1

Eve Freeman
Eve Freeman

Reputation: 33145

You mean like the scala script?

http://www.scala-lang.org/docu/files/tools/scala.html

Upvotes: 0

Related Questions