title: How to run a Scala script within IntelliJ IDEA?
body: <p>Here is a trivial scala script:</p>
  
  <pre><code>object test {
    def hi() { print("hi there from here") }
  }
  
  
  test.hi()
  </code></pre>
  
  <p>From the command line it does the expected: </p>
  
  <pre><code>scala /shared/scaladem/src/main/scala/test.scala
  Loading /shared/scaladem/src/main/scala/test.scala...
  defined module test
  hi there from here
  Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
  Type in expressions to have them evaluated.
  Type :help for more information.
  
  scala&gt;
  </code></pre>
  
  <p>But within Intellij it gives a compilation error.  Right click | Run test.scala </p>
  
  <pre><code>expected class or object definition
  test.hi()
  ^
  </code></pre>
  
  <p>BTW I also tried running as a scala worksheet. That was MUCH worse - tons of garbage output and did not even get close to compiling.</p>
  
  <p><strong>Update</strong>: it appears there is an older but similar question:</p>
  
  <p><strong><a href="https://stackoverflow.com/questions/7853860/how-to-run-scala-code-in-intellij-idea-10">How to run Scala code in Intellij Idea 10</a></strong></p>
  
  <p>I went into Run Configuration and unchecked "Make" as instructed (this was bothersome but so be it ..)</p>
  
  <p>However after making that change I get a different error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: scala/Either
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:190)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
  Caused by: java.lang.ClassNotFoundException: scala.Either
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 3 more
  </code></pre>
  
  <p>Note: the Scala-Library is properly set up:</p>
  
  <p><img src="https://i.stack.imgur.com/sarea.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/eABL6.png" alt="enter image description here"></p>
  
  <p><strong>Another update (after @lhuang's comment below)</strong>   I followed the suggestion to create another project from scratch. In that case a Scala Worksheet worked properly (test.sc). But a scala script (which works when running command line via "scala test.scala" )  still does <em>not</em> work, even in this brand new "scala" project. </p>