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.

link|flag

The answers are all missing the target. If you are writing a script, to be executed as a script, then there ought to be a way to execute it as such. This is not related to trying things on REPL, or different ways to generate a program instead of a script. – Daniel C. Sobral Oct 1 '09 at 13:17
Definitely. None of the answers is related to the question. I wonder why one of them was upvoted. – Elazar Leibovich Oct 1 '09 at 15:35

4 Answers

up vote 1 down vote accepted

If you have the scala distribution installed on the same machine, you can configure the "External Tools" to run scala scripts.

From the menu, select "Run" -> "External Tools" -> "External Tools Configurations...".
Highlight "Program" and create a new configuration.
Fill out the dialog like so:

"Main" tab:
Name: ScalaScriptRunner
Location: c:\path\to\scala\bin\scala.bat [or use the *nix equiv]
Working Directory: ${workspace_loc}
Arguments: ${resource_loc}

"Common" tab:
Check the "Display in Favorites" selection.

Click "Apply" and "Close".

Now, if you highlight a scala script file, you can run it from the toolbar. Note that this is independent of the scala eclipse plugin, and in fact, you may have to name your scripts a different extension (.scalascript?) if you have it installed.

link|flag
Yeah, I knew you can do that, but I'd rather use the integrated way. If the plugin would differentiate between a script and a program by the shebang (!#) or by allowing you to create a script - that would be great. – Elazar Leibovich Oct 9 '09 at 4:09

You can open an interactive shell by right-clicking on the project, selecting Scala-> Create interpreter in XYZ.

link|flag

If I recall correctly, the Scala Eclipse plugin comes with an interactive console in which you can execute your Scala script. Detail of how to activate it has escaped me since I haven't been using Eclipse for Scala development for a long time. Look it up, its there.

link|flag

Don't know about running a script from Eclipse, but you can do something like this:

object Main extends Application {
  println("Look, no main(args: Array[String])")
}
link|flag
1  
extend Application and using the primary constructor is not recommend for anything else than short "test programs" – Schildmeijer Oct 1 '09 at 19:44

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.