Working IntelliJ Scala Plugin Tutorial? - scala

I'm having some trouble getting the scala plugin to work with IntelliJ IDEA 10.5.1 Community Edition on Mac OSX 10.6.8. I'm following these instructions but whenever I try to run the simple HelloWorld application, I get this error:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -Didea.launcher.port=7533 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA 10 CE.app/bin -Dfile.encoding=UTF-8 -classpath /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/deploy.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/dt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javaws.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jconsole.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/management-agent.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/plugin.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/sa-jdi.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/alt-rt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/alt-string.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/charsets.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/classes.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar:/Users/A482930/IdeaProjects/ScalaPractice/out/production/ScalaPractice:/Users/A482930/scala/lib/scala-library.jar:/Users/A482930/scala/lib/scala-swing.jar:/Users/A482930/scala/lib/scala-dbc.jar:/Applications/IntelliJ IDEA 10 CE.app/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain HelloWorld
Exception in thread "main" java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Process finished with exit code 1
I checked the module settings and the compiler library seems to be set up correctly. The version of scala I'm using is the 2.9.0.1 with the IzPack Installer. I've tried both the IDEA plugin listed under available plugins as well as the July 5 2011 nightly here.
Rather then helping me troubleshoot my specific issue, does anyone know of a step by step tutorial that actually works without issues for a configuration similar to mine? I'm ok with using older versions of scala and even IDEA as long as they work.

I'm not sure you still need help with this, but I just ran a simple example with Scala 2.9.0.1 and it worked. I've been having tons of issues with the plugin though, so I guess it would help to know the exact steps you followed.
In my case, I did this:
Created Project
Added Scala Facet in the Project Wizard and added the Scala libs as a global lib (there are a few issues with this, but it should work here)
Create your HelloWorld example
Create a new Scala Compilation Server Runner. Add the Classpath of your project
Run the project

A colleague of mine created this some months ago, after having some issues getting started:
https://github.com/runeflobakk/sbt-idea-scalatest
Guess it is more SBT focused, but maybe you can find some use in it anyway?

Related

Groovy ClassNotFoundException: groovy.swing.factory.groovy$lang$Closure

In Eclipse I have for some reason since last week a weird error while using Groovy. I never seen this error before and a search shows that I seems to be the only one.
Caused by: java.lang.NoClassDefFoundError: groovy/swing/factory/groovy$lang$Closure
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3427)
at java.base/java.lang.Class.getMethods(Class.java:2019)
at org.junit.platform.commons.util.ReflectionUtils.getDefaultMethods(ReflectionUtils.java:1518)
at org.junit.platform.commons.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:1491)
at org.junit.platform.commons.util.ReflectionUtils.findMethod(ReflectionUtils.java:1341)
at org.junit.platform.commons.util.ReflectionUtils.isMethodPresent(ReflectionUtils.java:1242)
I have no clue why I get this. I'm not using Swing or Groovy Swing anywhere. It's not JUnit 5 related because I got this also from Guice.
This should be related with Eclipse because if I compile it in Maven it runs fine. Currently I need to do a mvn clean install so that it runs again in Eclipse.
Eclipse Version: 2022-06 (4.24.0)
Build id: 20220609-1112
Groovy 3.0.14
Run in Eclipse. Groovy is added as dependency. It should run without errors.

Error running Scala tests in Intelli-J

I'm having some problems getting my Scala tests running via the Intelli-J Run/Debug configuration. The tests are working if I run them directly in the SBT console.
My configuration looks like this:
I'm getting this error in the Run console panel:
java.lang.IllegalArgumentException: ERROR: -r has been deprecated for a very long time and is no longer supported, to prepare for reusing it for a different purpose in the near future. Please change all uses of -r to -C.
at org.scalatest.tools.ArgsParser$.checkArgsForValidity(ArgsParser.scala:41)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:857)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:141)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
I've checked my plugins are all up-to-date. Do I need to use a particular version of Scala? Or is there some additional setup I'm missing?
For anyone who has this problem even with newer version of IntelliJ, here is how I went about figuring out where the issue was. I pulled in the scalatest dependency at the top of the pom for the module I was trying to run tests in. Then an individual test would run without this error. I moved the dependency down the pom until the problem recurred to figure out which dependency was causing the problem. Then I found that the dependency had some really old dependencies including an older version of scalatest that weren't showing up in my dependency tree. Also, this jar dependency had scalatest as a dependency not marked with scope test.
It appears to have been a problem with the Scala plugin under Intelli-J 13.
I fixed this by upgrading to Intelli-J 2016.3, which I presume has been changed to pass the newer -C switch to ScalaTestRunner.
#JasonF pointed out in his comment below that a project dependency can also cause a problem with the scalatest plugin (this was the case for him). It's worth attempting to run the tests of a fresh sample Scala project to test for this scenario before upgrading the IDE.

Running IntelliJ scala project error

I am not using IntelliJ 15 for a long time, but never ever had such an issue. When I do: New Project -> Scala, then everything works fine, but when I do New Project -> SBT, then I can't even have main, because it gives me this:
Exception in thread "main" java.lang.ClassNotFoundException: testing
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
I did try deleting Make from Edit Configurations, I also tried adding Scala script in Edit Configurations, but still have this problem (it says scala script couldn't be found even though I linked it properly). Also, I read this topic:
How to run a Scala script within IntelliJ IDEA?
but haven't found solution. Thank you for your suggestions.
Took me some time, but fixed - the problem was pretty much obvious. It was enough to go: File -> Project Structure -> Modules and add to Source Folders places where you create your scala file, or simply create scala script file in main -> scala.

ClassNotFoundException when running my plugins in a new eclipse configuration instance

I am running two eclipse plugins that I developped. These plugins are successfully imported to the new workspace within the persisted container Library. So far everything is OK, the problems started while I was trying to test my plugins :
1) I couldn't neither gain from eclipse's text auto-completion to navigate the classes of my plugins or their methods
2) When I run this test I get a classNotfoundException here is the error :
Caused by: java.lang.ClassNotFoundException:
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main"
Trying to remedy to this problem, I applied the solution proposed by eran_levi : "Running my eclipse plugin end up with ClassNotFoundException" but it didn't work for me.
Any sort of help is really appreciated.
Thank you in Advance !!!
I wanted to play clever and I didn't export all the plugins while defining the running configuration (only my two plugins and some equinox plugins). When I imported all the plugins everything worked well.

Intellij will not run ScalaTests - "Incompatible Class Change Error"

I'm trying to run tests for an sbt-based Scala application in intellij. But I get the following error which I'm not sure how to fix:
Testing started at 21:07 ...
java.lang.IncompatibleClassChangeError: Found class scala.collection.mutable.ArrayOps, but interface was expected
at org.scalatest.tools.Runner$.checkArgsForValidity(Runner.scala:895)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:729)
at org.scalatest.tools.Runner$.run(Runner.scala:711)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:144)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
When I decorate my classes with the Junit runner attribute they work fine (and it's actually a much better run in terms of the visuals):
#RunWith(classOf[JUnitRunner])
I got the same error when trying to run tests for my Play Framework app. Drilling down into the stack trace, I found that the problem class was FakeRequest, which is in the play-test library. I had two different versions of the library, one for Play 2.4 and one for 2.3. I was able to resolve this issue by removing the play-test version for Play 2.3 (open Module Settings -> Libraries -> find and delete the bad dependency).
Your issue is probably with some other problematic dependency, but following the same steps as above may help fix it.
This seems to be a problem with scala test runner framework. I had come across the same problem; eventually like you suggested end up using junit test runner to make it work. But the problem in my case was it was pulling in a transitive dependency and no such class error.
Make sure the libraries what you are using for the JUnitRunner are same. Most of the times “Incompatible Class Change Error” occurs because of backward compatibility. And also have a look at scala library jar at the time of compiling and running.