score:23
With the Scala plugin installed either
A. Create a new project and select the Scala facet in the creation phase. It will create the Scala library lib and Scala compiler lib and setup the facet for you
B. If you already have a project. Go to Project Structure -> Modules and right click the module and go Add facet and add a Scala facet. Now you need to add scala-library.jar as a library of the module and go into the Scala facet and point it to a library containing scala-compiler.jar
Some more information
this is what your module should look like under project settings
select the Scala facet and this is what you should see (Library name for the compiler is unimportant as long as it says (version xxx) next to the library name
these are the jar files in my scala-compiler lib
and these are the jar files in my scala-library lib
With everything setup like that you should be able to right click -> new Scala class (Select object from the dropdown) in a source directory and add
def main(args:Array[String]) {
println("Hello world")
}
then right click on the class and select Run Classnam.main() and IntelliJ will setup a run configuration for you.
score:2
Use sbt with sbt-idea plugin to generate idea project files for complex projects.
Or
For simple projects.
Add scala nature to the project, and you can right click and run any file extending App.
score:2
A good walk-through on how to set up a Scala project in Intellij is located here: http://sonyarouje.com/2011/03/18/running-scala-in-intellij-idea-10/
score:11
Edit: I can see someone posted somewhat the same I want to say here. I hope this can give a few more in-depths hints, so I will post it anyway :-)
If you would like to run Scala native in IntelliJ (I shifted to IntelliJ and still can't get my hands down) you need to make sure a few things are in order. Most of this happens under File -> Project Structure which requires you to create a project (when you get a hang of it, it is much more logical than Eclipse -- and Netbeans for that matter). I am also assuming you have selected a jdk, but this can also be done in the Project Structure.
Now, to Scala:
- Make sure you have the Scala plugin. Visit the Settings (File -> Settings; can also be found at the start-up screen) and locate 'Plugins' (for me it's nr. 8 from the bottom). Under "Browse Repositories" you should be able to search for "scala", find and install a plugin. 1 A. If no plugins pops up you are probably using a version of intellij where scala is not (yet) supported. If that happens you can go to the homepage for the plugin and download the nightly build.
- Import Scala as a library in File -> Project Structure -> Global Libraries. Click the plus sign, select Java (Scala is a Java-lib), browse to your scala-dir (which can be downloaded here: http://plugins.intellij.net/plugin/?id=1347) and select the lib directory. Press ok and you should see the library popping up on the list.
- Make sure the facet (Scala framework) is in place. Goto File -> Project Structure -> Facets. Click on the plus-sign and find Scala. A sublink should appear (if not double-click the Scala link). Clicking the sublink make sure you have selected a compiler before continuing. This should be provided by the modules selected before. I normally use FSC (Fast Scala Compiler) but it's probably a good idea to test the basic settings before experimenting.
- Make sure the Scala Module is in place. In Project Structure -> Modules click on the module you want to compile in scala and click the plus icon above and select Scala. Again be sure to select a compiler library.
- If you want to, setup configurations for the compiler under the facet
Source: stackoverflow.com
Related Query
- How to run scala code on Intellij Idea 11?
- How to run Scala code in Intellij Idea 10
- How to run tests on every code change in IntelliJ IDEA from Scala sbt project?
- How to configure code style for Scala in IntelliJ IDEA
- Scala code compiles through command-line sbt but fails when compiled through Intellij Idea - how set up Intellij to use external sbt?
- How to create xml scala code format schema for IntelliJ IDEA
- How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?
- How to run a Scala script within IntelliJ IDEA?
- How to add Jar libraries to an IntelliJ Idea SBT Scala project?
- How do I change intellij idea to compile with scala 2.11?
- How to setup Intellij 14 Scala Worksheet to run Spark
- How do I run a scala ScalaTest in IntelliJ idea?
- reader writer state monad - how to run this scala code
- How to debug a scala based Spark program on Intellij IDEA
- How to get Scala imports working in IntelliJ IDEA with the Play framework?
- How to set up Java and Scala in one single Module in Intellij IDEA 11?
- How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.0?
- How to run Spark Scala code on Amazon EMR
- How to know if a Scala file modified with IntelliJ Idea is saved and if it is checked into CVS?
- How to run a spark example program in Intellij IDEA
- How to set up an IntelliJ Idea Scala project to recognize local Ivy2 cache?
- How to compile and run scala code quickly in vim?
- How to run JavaScript code from within Scala (JVM)?
- How do I make intellij Idea to highlight Scala script correctly with #! (shebang)
- Partial EMMA code coverage in Scala Case Class for IntelliJ IDEA 10.5
- Intellij not able to run Scala Code
- How to custom code folding for Scala in intelliJ IDEA?
- Getting "Internal error: Scala instance doesn't exist or is invalid" when trying to run a worksheet in IntelliJ IDEA
- How to run python code with args with python -c command from scala
- How to create an SBT Run configuration in IntelliJ IDEA 11 Community Edition?
More Query from same tag
- escaping effect Monad vs. not escaping
- How debug spark dropduplicate and join function calls?
- Scala 2.9.2 Simple string Interpolation Throwing Error
- Selecting the Minumum Sized List in a List of List
- In Scala, is there a way to represent price as $Y.YY?
- Convert java to scala code
- Scala object constructor
- Modify json field type via circe
- How to replace values in RDD 1 per keys in RDD 2?
- In Scala, can you make an instance with variable refering to other class or trait?
- Scala - hashCode caching for immutable collections
- Akka HTTP / Error Response entity was not subscribed after 1 second
- Type parameter issue in Scala with generic function
- Spark dataframe filter
- Creating a modified `filter` function
- Jsoup select not returning all elements
- Unable to run custom sbt task from AutoPlugin's command
- Could not find implicit value for parameter in scala
- Merge multiple individual entries to single entry in Spark Dataframe
- Can a predicate be explicitly defined?
- Convert Either[A, B] to Option[A] where Left becomes Some
- Filter spark paths on `input_file_name`
- Intersection of Two HashMap (HashMap<Integer,HashSet<Integer>>) RDDs in Scala for Spark
- Apache Spark performance tuning
- Adaptive Maps in Scala (or Java) Preserving Insertion Order
- Play framework WS set cookie
- Cost of Builder#result for immutable collections?
- scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result
- toMap error in mapping a Data Set
- How Can I Share Code Between Integration Tests and Unit Tests