Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 241
Kai Wähner Avatar asked Feb 17 '12 09:02

Kai Wähner


People also ask

Can you mix Java and Scala?

Is it possible to mix Scala and Java code? Yes, there is the ability to mix both types of code. It is possible to create an SBT project, put Scala code in src/main/scala and java code in src/main/java in the same project and make it work.

How do I run one module in IntelliJ?

Import a module from existing sourcesFrom the main menu, select File | New | Module from Existing Sources. Select the directory in which your sources, libraries, and other assets are located and click Open.

How do I create a multi module Maven project in IntelliJ?

In the Project tool window, right-click the project folder and select New | Module. Alternatively, from the main menu, select File| New | Module to open the New Module wizard. If you used main menu to add a module then the process of adding a module is the same as Creating a new Maven project.


2 Answers

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

like image 166
Kai Wähner Avatar answered Sep 30 '22 19:09

Kai Wähner


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

like image 34
Gyanendra Dwivedi Avatar answered Sep 30 '22 19:09

Gyanendra Dwivedi