Kai Wähner
Kai Wähner

Reputation: 5430

How to set up Java and Scala in one single Module in Intellij IDEA 11?

I have got IntelliJ 11. I use Maven for dependency management.

I want to create one module which contains Java and Scala source files. I have already added a folder "src/main/java" and "src/main/scala" under Project Settings => Module => "Module XYZ". The Scala facet is also added already.

What do I need to make IntelliJ compile both correctly?

Upvotes: 13

Views: 15433

Answers (2)

Gyanendra Dwivedi
Gyanendra Dwivedi

Reputation: 5537

To create a new project that uses Scala:

  1. In "New Project" wizard check "Scala" in technologies list.
  2. Provide a path to Scala installation (if not detected)

To add a new module that uses Scala into existing project:

  1. In "Add Module" wizard check "Scala" in technologies list.
  2. Provide a path to Scala installation (if not detected)

To add Scala support to existing module:

  1. Right-click the module in Project View, choose "Add Framework Support..."
  2. Check "Scala" in technologies list (unavailable if module has Scala facet attached)
  3. Provide a path to Scala installation (if not detected)

To manually configure existing module:

  1. Create library "scala-compiler":

    • Classes:

      • scala-compiler.jar
      • scala-library.jar
  2. Create library "scala-library":

    • Classes:

      • scala-dbc.jar
      • scala-library.jar
      • scala-swing.jar
    • Sources:

      • scala-dbc-src.jar
      • library-src.jar
      • swing-src.jar

Docs: /doc/scala-devel-docs/api/

(if you downloaded Scala as an archive, you need to get separate API docs archive and extract it so that \doc\scala-devel-docs\api exist; if you installed Scala using LzPack, then API docs are already there)

  1. Add Scala facet to the module, select "scala-compiler" library as compiler library
  2. Add "scala-library" to module dependencies.

Hints:

  • Don't add Scala compiler library to module dependencies (unless you really need Scala compiler classes in your code)
  • Remember to attach "scala-library*.jar" to Scala compiler library, it's a dependency of "scala-compiler*.jar" itself.

Source: Project-configuration-explained

Upvotes: 2

Kai Wähner
Kai Wähner

Reputation: 5430

I did not find a good Google result first. Got it working now. This site explains it very clearly:

http://devnet.jetbrains.net/thread/290032

Upvotes: 21

Related Questions