Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Scala as a scripting language from Eclipse

Is there a way to execute a scala script from Eclipse with scala plugin?

A scala script is a scala file which is executed line by line, without forcing you to write a main method. See the Description section in scala's man page.

like image 722
Elazar Leibovich Avatar asked Oct 01 '09 05:10

Elazar Leibovich


People also ask

Is Scala a scripting language?

You want to use Scala as a scripting language on Unix systems, replacing other scripts you've written in a Unix shell (Bourne Shell, Bash), Perl, PHP, Ruby, etc.


1 Answers

I know this question is ancient at this point, but on the off chance that someone is looking for the answer (as I was), here we go. This information is based on the beta 2.0.0.0 release of the Scala Eclipse Plug-in using Scala 2.8.2. I found 2 possible options available:

The first option is to use the "Send Selection to Scala Interpreter" command which is bound to "Ctr+Shift+X" by default. This will take the current text selection in any Scala editor and send it to the interpreter for execution. It creates a new window in the same tab grouping as the Eclipse console. There does appear to be one issue with this in that you get the error ":3: error: value tools is not a member of package scala" at the end of the execution. This is an acknowledged issue and I found workarounds for Inteli-J, but not Eclipse.

The second option (which is the one I'm currently using) is to create a new "Run Configuration" for the Scala interpreter. If go to "Run...Run Configurations" you should see "Scala Interpreter" listed as one of the launchers. You can create a new configuration for this launcher with all default options and when you run it you get the scala interpreter prompt in your console window. From here you can script to your hearts content. You should be able to get it to run script files this way as well, by defining the proper run configurations (though I haven't done that yet).

Hopefully this will be of some use to someone.

like image 80
sfitts Avatar answered Oct 13 '22 06:10

sfitts