views:

2271

answers:

9

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far.

I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to 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 plug-in.

Then I setup a project from scratch through the wizards:

  • new project from scratch
  • JDK is 1.6.u20
  • accept the default (project) instead of global / module
  • accept the download of Scala 2.8.0beta1 into project's lib folder

Created a new class:

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

For my efforts, I now have a brand-new error :)

Here it 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.java:190), java.lang.ClassLoader.loadClass(ClassLoader.java:307), sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301), 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 went with the 2.7.3 version of Scala rather than the default 2.7.6, because 2.7.3 is the one shown in the screen-shots at the IntelliJ website (I guess the screen-shots prove that they actually tested this version!). Now everything works!!!

+1  A: 

You are mixing code compiled with two different Scala versions.

Daniel
That's impossible... it's only a 3-line "hello world" program!
Alex R
That is a non-sequitur!
Randall Schulz
no, really ... 3 lines of code cannot possibly have been "compiled with two different Scala versions". There is a possibility IntelliJ is finding files from prior experiments; so I'm going to try a full uninstall/reinstall now.
Alex R
ok it was 5 lines not 3, but still!
Alex R
BTW what IDE do you use? Thanks
Alex R
Me? I use IDEA. I find it works well and has for quite a while. As to the mixed-version hypothesis, it applies across all the code, so you have to execute with libraries compiled by the same version of the Scala compiler as that with which your own code was compiled.
Randall Schulz
A: 

To say more about this, you have to tell us how you got to where you are. Did you define a library (global or module-specific) for the Scala version you want to use? You should always do this rather than rely on any automatic provision of a Scala library and compiler from the plug-in.

I think this problem would be better resolved interactively. We do this fairly often on #scala, so maybe you could try there?

Randall Schulz
I defined the library as project-wide, which was the default. I used the automatic provision feature, which downloaded scala 2.7.6 straight into the project's lib folder.
Alex R
I know re-did everything with IDEA 9.0.2 EA, and Scala 2.8.0beta1. Still no luck. What IDE do you use? Thanks
Alex R
@Alex I use IDEA 95.24, but I must say that I do not _compile_ my projects with IDEA. Instead, I use SBT for all my building needs.
Daniel
+6  A: 

Hi Alex,

To answer your question, it's difficult to get a working IDE for Scala for two reasons: (a) Scala is only just beginning to reach a wide audience and (b) due to (a), there is no business case for spending time on a Scala IDE.

Also, if you are old enough to cast 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 with okay-ish tools like JBuilder that did little more than compile your code when you said so - no error highlighting, no auto-importing, and the word refactoring didn't even exist. If you want to pioneer, you need to be prepared to cut some of the road yourself, or at least bush-bash.

I know it won't help you, but I have successfully used IDEA for Scala on Linux, Mac and Windows. I typically have the Scala SDK installed somewhere locally and point IDEA at that rather than using the 'download' option.

Presently, I am mostly using an EAP version of IDEA 9 on Mac OS X with Scala 2.8.0.Beta1-RC5 and it's working well (except that fsc doesn't seem to worked with mixed sources).

You could try your luck over at the IDEA Scala Plugin Discussion Forum, though I haven't had a great lot of responses to my own postings there.

Graham Lea
+2  A: 

I had the same problem yesterday while trying to set it up. Solution is pretty simple, you just have to set scala somewhere in project settings.

Theq
I did go to Settings to add the Scala Plugin. Is there something ELSE I need to do? Thanks
Alex R
The only unobvious thing thats not on main tutorial is to add scala library to yours module dependency. This is in Module setting -> dependecies tab AFAIR. Works perfectly even with 2.8 rc.
Theq
A: 

Scala just isn't used enough to warrant the investment to create IDEs for it. Mainly it's a hobby language of a few people for academic interest only.

I was in fact more than a bit surprised that Jetbrains expended any resources at all in adding support for it to their flagship product.

jwenting
The fact that Java did not have a good IDE support does not make Java "a hobby language".
The "big three" Java IDEs (IDEA, NetBeans and Eclipse) all have some degree of support for Scala.
Randall Schulz
I think you've disproved your own assertion. If Jetbrains is *spending money* to add support for it, obviously they think it's not just a hobby language, and they are probably in the best position to judge.
Graham Lea
I do say I'm surprised at their investment. They clearly don't have the same opinion about Scala that I do, else there's no economic reason for the investment and I don't think they'd spend the money if they didn't think it economically viable.
jwenting
Perhaps your opinion about Scala should be re-assessed. You talk of it being 'of academic interest only'. There are many in the community to date obsessed with the academic properties of the language, and they have been vocal, which has skewed its image. But it is a highly practical and applicable language and is a vast improvement on Java-the-language. Abandon your fear and embrace Scala.
Synesso
@Synesso Oh, but what Scala gives up to leave academia and play nice with Java!
pst
I see the Java vs Scala debate at lot like C vs C++ in the early '90s. C++ was new. C++ specifications were unstable. C++ would never catch on in the corporate world. In a way, they were right - C++ "never caught on" - just look at the staggering vast amounts of C code that have been written since C++ has been out - projects that could have taken advantage of C++ but chose not to. But we can in fact say that C++ today is stable, and the irrational fears are gone. Rational reasons to not use C++ still exist and always will for Scala.
Alex R
+3  A: 

Installing the plug-in is prerequisite one.

The next thing you should do is define a library (global or project-specific; I use global) that holds the Scala library and compiler JAR files (at a minimum, that's scala-compiler.jar and scala-library.jar). Adding source JARs and a documentation JAR or URLs is a good idea, too. Then make this library a dependency of any modules in your project that include Scala code.

Lastly, find the Scala facets in those modules and de-select both check-boxes there.

Randall Schulz
+10  A: 

I have encountered the same scalac error when trying to run a Scala project in Intellij Idea 9.0.2 and I've managed to find a solution by chance :). These are the steps I took in creating the project and running it.

I have created a Scala project in Intellij Idea 9.0.2 final (it was released today). I have installed the Scala plugin, restarted the IDE and created a new Scala project (with the name "TestScala") with scala-2.8.0.Beta1 as project library. Once the project is created and the scala libraries downloaded, I have created a Test.scala file with the following content:

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

After that, I created a launch configuration ("Edit Configurations"), choosing the "Application" template. I set as main class Test and choose the project name ("TestScala") in the "Use classpath and JDK of module" combo box. When I run the configuration I get the same error as you reported ("Scalac internal error: class java.lang.ClassNotFoundException") .

Now comes the freaky part :). I right click on the project, choose "Module Settings", have a look on all settings but I don't change anything . Click "apply" and "ok", try to run configuration again and it works :) .

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

UPDATE:

When checking the setting of the module, one needs to click on the Module->Scala and Facets->Scala (expand it and click on Scala(ProjectName)) . Both of these settings are about the scala compiler and scala library location. I would guess these values are not properly set when the project is created but are saved once the user touches them and saves the settings.

Thanks! This is consistent with what I observed, but was not immediately obvious until I saw your answer!
Alex R
OMG! Thanks a lot for this hint! Saved my much much much trouble! :)
Malax
Genius.Thank you, and I will blame the IntelliJ developers at the next possible occasion.
Alexander Temerev
A: 

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

Bruce Li
+1  A: 

I just did a fresh install and had exactly this same problem myself. It turned out that, because I had created the file in the root package, IDEA had added a package statement at the top with naming a package. I assume that this then got compiled as "package object Main" - valid syntax in 2.8? Anyway, I deleted the line that said package and it all worked fine.

Graham Lea