How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic things like termination don't work). So now I'm trying IntelliJ. I'm not very far.

I was able to edit programs (in syntax highlighting and completion ... yay!). But I can’t run even the simplest "Hello World". This was the original error:

 Scala signature Predef has wrong version
 Expected 5.0
 found: 4.1 in .... scala-library.jar

But that was yesterday with IDEA 9.0.1. See below...

UPDATE

Today I uninstalled IntelliJ 9.0.1 and installed 9.0.2 Early Availability with the 4/14 stable version of the Scala plugin.

Then I set up the project from scratch through the wizards:

  • new project from scratch
  • JDK - 1.6.u20
  • accept default value (project) instead of global / module
  • accept download Scala 2.8.0beta1 to lib project folder

Created a new class:

 object hello {
   def main (args: Array [String]) {
     println ("hello:" + args);
   }
 }

For my efforts, I now have a whole new mistake :)

There he is:

Scalac internal error: class java.lang.ClassNotFoundException [java.net.URLClassLoader $ 1.run (URLClassLoader.java:202), java.security.AccessController.doPrivileged (native method), java.net.URLClassLoader.findClass (URLClassLoader : 190), java.lang.ClassLoader.loadClass (ClassLoader.java.307), sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.javahaps01), java.lang.ClassLoader.loadClass (ClassLoader.java: 248) , java.lang.Class.forName0 (Native Method), java.lang.Class.forName (Class.java:169), org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main (ScalacRunner.java: 72) ]

FINAL UPDATE

I uninstalled 9.0.2 EA and reinstalled 9.0.1, but this time I went with Scala version 2.7.3 and not the default 2.7.6, because 2.7.3 is the one shown in the screenshots on the web IntelliJ website (I think the screenshots prove that they really tested this version!). Now everything works !!!

+47
scala intellij-idea
Apr 19 '10 at 14:25
source share
9 answers

I encountered the same scalac error when trying to start a Scala project in Intellij Idea 9.0.2, and I managed to find a solution by accident :). These are the steps that I took when creating the project and starting it.

I created the Scala project in the final Intellij Idea 9.0.2 (it was released today). I installed the Scala plugin, restarted the IDE, and created a new Scala project (named "TestScala") with scala -2.8.0.Beta1 as the project library. After creating the project and loading the Scala libraries, I created a Test.scala file with the following contents:

object Test { def main(args:Array[String]){ println("hello") } } 

After that, I created the launch configuration (“Edit Configurations”) by selecting the “Application” template. I installed the main test of the class and select the project name ("TestScala") in the "Use class of path and module JDK" field. When I run the configuration, I get the same error as you reported ("Scalac internal error: class java.lang.ClassNotFoundException").

Now comes the weird part :). I right-click on the project, select "Module Settings", view all the settings, but do not change anything . Click "apply" and "OK", try to run the configuration again and it works :).

I am using Intellij Idea 9.0.2 final release (build 95-66); Ubuntu 9.10 and JDK 1.6.0_18. I should also mention that I had a JDK configured in Intellij, otherwise there is an extra step to configure it.

UPDATE:

When checking the installation of the module, click on Module → Scala and Borders → Scala (expand it and click Scala (ProjectName)) . Both of these options apply to the Scala and Scala linker. I would suggest that these values ​​are incorrectly set when creating the project, but remain after the user touches them and saves the settings.

+20
Apr 22 '10 at 7:00
source share

To answer your question, it is difficult to get an IDE working environment for Scala for two reasons: (a) Scala is just starting to reach a wide audience and (b) because of (a) there is no business case for spending time in the Scala IDE.

Also, if you are old enough to throw your mind back and young enough to still remember, you would know that for the first five or more years of Java, we were stuck in good tools like JBuilder that did a little more than compile your code when you say this - no error is highlighted, no auto-import, and the word refactoring does not even exist. If you want to become a pioneer, you need to be prepared to cut off part of the road yourself, or at least a bash shrub.

I know that this will not help you, but I have successfully used IDEA for Scala for Linux, Mac and Windows. Usually I install the Scala SDK somewhere locally and specify IDEA rather than using the download option.

Currently, I mainly use the EAP version of IDEA 9 on Mac OS X with Scala 2.8.0.Beta1-RC5 and it works well (except that fsc does not work with mixed sources).

You can try your luck at the IDEA Scala plugin discussion forum , although I didn't have a lot of answers to my own posts there.

+10
Apr 20 '10 at 10:54
source share

Installing the plugin is a prerequisite.

The next thing you need to do is define a library (global or project specific, I use global) that contains the Scala and JAR libraries of the compiler (at least scala-compiler.jar and scala-library.jar ). Adding source JARs and JARs to documentation or URLs is also a good idea. Then make this library dependent on any modules in your project that include Scala code.

Finally, find the Scala faces in these modules and deselect the checkboxes.

+6
Apr 20 '10 at 14:46
source share

I just did a new installation and had the same problem. It turned out that since I created the file in the root package, IDEA added the package statement at the top, naming the package. I assume this is then compiled as the "main package object" - valid syntax in 2.8? Anyway, I deleted the line where the package is indicated, and all this worked fine.

+2
Jun 07 2018-10-10T00:
source share

Yesterday I had the same problem trying to set it up. The solution is quite simple, you just need to install scala somewhere in the project settings.

+1
Apr 20 2018-10-11T00:
source share

You are mixing code compiled with two different versions of Scala.

0
Apr 19 '10 at 14:57
source share

I use Netbeans to write scala programs. So far, this works well with my codes. You can try the plugin here: http://wiki.netbeans.org/Scala68v1 .

0
May 17 '10 at 9:47 a.m.
source share

I was getting this error, and also had to right-click on the project and "Open module settings". However, it was more than just a hit. I had to make sure my root content was correct for each project. For some reason, there were some incorrect source and test folders.

My project uses maven as the main build tool, and importing the project into Intellij probably created these incorrect settings.

0
Jan 26 '11 at 18:16
source share

I had a similar problem, following this instructions on the blog solved the problem for me

0
Aug 26 '11 at 11:55
source share



All Articles