Here is a trivial scala script:
object test {
def hi() { print(\"hi there from here\") }
}
test.hi()
From the command line it does the expe
What works for me, is:
Now you can run your script. It's a bit inconvenient, but it works.
Note: This works for me in IntelliJ IDEA 14.x
Your code works in command line because it is "script", when you want to make it runnable in project there are ways to do it:
By creating object which extends App
object test {
def hi() { print("hi there from here") }
}
object runnable extends App {
test.hi()
}
or java-like solution i.e. creating main method
object test {
def hi() { print("hi there from here") }
}
object runnable {
def main(args: Array[String]) {
test.hi()
}
}
when need to execute as script - I do it like that: select code to execute by mouse, then choose from context menu "Send Selection To Scala Console"
There are 2 things to understand first. Scala works as both interpreter and compiler. You are trying to with interpreter "scala test.scala" without using "scalac test.scala" and interpreter works without main method also.
Other way you can do in intellij is open the terminal or command prompt in intellij and run scala test.scala from the file location (Pre-requisite is scala in present the system path)
The answer here is a combination of items:
This shows rough edges with Intellij and its scala plugin. Especially when I want to integrate scala with java it is apparently difficult if even possible using Intellij at this time (need to create new Scala project on a frequent basis is a non-starter for mostly java projects attempting to incorporate scala).
But for scala-first projects it seems this may be workable.