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.
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.
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.
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.
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])")
}
Application. The code runs as if it's in the main() function, not in a constructor.