This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Run scala script without installing scala?

2 replies
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.

You also need scala-compiler.jar. You need to run a class in there called something like MainGenericRunner maybe.

-------------------------------------
jlist9 wrote:

Hi,

I have a simple scala script. Is it possible, with JRE and
scala-library.jar, to execute
the script without installing scala, and without compiling the script?

Thanks

bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 40 weeks ago.
Re: Run scala script without installing scala?

A little bit of FireBugs spelunking reveals the correct URL pattern is:

http://www.simplyscala.com/interp?code=...

This executes the "code" param value, and returns an HTML fragment
that includes both the original source and (apparently) the sysout
stream generated by the code when executed.

Best regards,
Brian Maso
(949) 395-8551
brian@blumenfeld-maso.com
twitter: @bmaso
skype: brian.maso
LinkedIn: http://www.linkedin.com/in/brianmaso

On Fri, Mar 5, 2010 at 2:38 PM, Brian Maso wrote:
> Hmmm.. SOund really intreagueing, but I can't this to do anything at
> all. Can you give an example of a "simplyscala" URL that interprets
> and runs, say, a HelloWorld program?
>
> Best regards,
> Brian Maso
> (949) 395-8551
> brian@blumenfeld-maso.com
> twitter: @bmaso
> skype: brian.maso
> LinkedIn: http://www.linkedin.com/in/brianmaso
>
> On Fri, Mar 5, 2010 at 11:55 AM, Paul Phillips wrote:
>> On Fri, Mar 05, 2010 at 11:43:17AM -0800, jlist9 wrote:
>>> I have a simple scala script. Is it possible, with JRE and
>>> scala-library.jar, to execute the script without installing scala, and
>>> without compiling the script?
>>
>> Nothing presently on this earth can execute it without compiling it.
>> The so-called "interpreter" is really a "quietly compile and run"-er.
>> However if we ignore that condition, sure.  The code which does so will
>> include a line something like
>>
>>  new java.net.URL("http://www.simplyscala.com/interp?" + code)
>>
>> and there you have it.  You don't even need scala-library.jar!
>>
>> --
>> Paul Phillips      | If this is raisin, make toast with it.
>> Imperfectionist    |
>> Empiricist         |
>> pp: i haul pills   |----------* http://www.improving.org/paulp/ *----------
>>
>

ewilligers
Joined: 2008-08-20,
User offline. Last seen 3 years 17 weeks ago.
Re: Run scala script without installing scala?

Naftoli Gugenheim wrote:
> You also need scala-compiler.jar. You need to run a class in there called something like MainGenericRunner maybe.

Yes.

Are you using a unix, or Window? Have a look at bin/scala or bin/scala.bat

"%_JAVACMD%" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%"
scala.tools.nsc.MainGenericRunner %_ARGS%

exec "${JAVACMD:=java}" $JAVA_OPTS -cp "$TOOL_CLASSPATH"
-Dscala.home="$SCALA_HOME" -Denv.classpath="$CLASSPATH"
-Denv.emacs="$EMACS" scala.tools.nsc.MainGenericRunner "$@"

Your command line will look something like

java -cp "scala-library.jar;scala-compiler.jar;."
scala.tools.nsc.MainGenericRunner -howtorun:script -savecompiled
-nocompdaemon scriptName

(use : instead of ; on unix)

I'm not suggesting that you should use -savecompiled and -nocompdaemon,
only that you should consider each of them.

Option -savecompiled requests that the compiled script be saved for
future use. This improves startup time for all runs except the first. It
obviously isn't useful if you are running from a read-only directory.

Option -nocompdaemon requests that the fsc offline compiler not be used.
The compiler daemon is not useful if you have several scripts, each for
a different version of the Scala compiler. It may confuse users, they
just want to run your script. It is helpful for compiler startup time
while you are developing your script.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland