Trying to run Scala test, getting java.lang.ClassNotFoundException: org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner - scala

I have a Gradle project in IntelliJ IDEA 2016.2. Everytime I run the Scala tests in the project, I get the following exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:48)
Caused by: java.lang.ClassNotFoundException: org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
... 5 more
I checked the versions of the dependencies and I have added the Scala SDK to the project module as well. I also added the Scala plugin to the Gradle file and installed the Scala plugin in IntelliJ IDEA. Also, the tests run without an error on my colleague's computer so we have no idea what the error could be.

Found the cause: I have an accentuated letter in my user directory's name and IDEA is always trying to use some file from AppData under that directory. I have already changed the idea.properties file, but it has no effect regarding that file.
A possible workaround is using gradle (or maven/sbt/etc.). In my case, I use gradle, I just add #RunWith(classOf[JUnitRunner]) to the scala class I want to test, then execute gradle's test task.

For me the solution of command line length limitation was crucial. Idea offers about 3 ways of how to overcome too long command. Choose another and check.
It's in run configurations.

Related

How to use scala.js compiler as a compiler plugin, thus allowing it to integrate into Gradle or maven?

I have a Scala project that can only be compiled with Gradle, recently someone has asked it to be ported to Scala.js, ideally by cross-build.
When I read the code of Scala.js, I realised that the bulk of the plugin is actually a compiler (scalac) plugin:
import scala.tools.nsc.plugins.{
Plugin => NscPlugin, PluginComponent => NscPluginComponent
}
...
class ScalaJSPlugin(val global: Global) extends NscPlugin {
import global._
...
But all the documentations have suggested to use it as part of the sbt-plugin, which are useless in my case. So I try to attach it to my scalac process, invoked through gradle:
dependencies {
implementation("org.scala-js:scalajs-library_${vs.scalaBinaryV}:${vs.scalaJSV}")
scalaCompilerPlugins("org.scala-js:scalajs-compiler_${vs.scalaV}:${vs.scalaJSV}")
...
This experiment unfortunately doesn't work. The compiler threw the following error:
> Task :compileTestFixturesScala FAILED
## Exception when compiling 1 sources to /home/peng/git-scaffold/scaffold-gradle-kts/build/classes/scala/testFixtures
scala.reflect.internal.MissingRequirementError: object scala.scalajs.js.Dynamic in compiler mirror not found.
scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:24)
scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$6(Mirrors.scala:66)
scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:56)
scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:56)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamicClass$lzycompute(JSDefinitions.scala:52)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamicClass(JSDefinitions.scala:52)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamicModule$lzycompute(JSDefinitions.scala:83)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamicModule(JSDefinitions.scala:83)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamic_newInstance$lzycompute(JSDefinitions.scala:84)
org.scalajs.nscplugin.JSDefinitions$JSDefinitionsClass.JSDynamic_newInstance(JSDefinitions.scala:84)
org.scalajs.nscplugin.JSPrimitives.initWithPrimitives(JSPrimitives.scala:89)
org.scalajs.nscplugin.JSPrimitives.initPrepJSPrimitives(JSPrimitives.scala:77)
org.scalajs.nscplugin.PrepJSInterop$JSInteropPhase.run(PrepJSInterop.scala:65)
scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1524)
scala.tools.nsc.Global$Run.compileUnits(Global.scala:1508)
scala.tools.nsc.Global$Run.compileSources(Global.scala:1500)
scala.tools.nsc.Global$Run.compile(Global.scala:1634)
xsbt.CachedCompiler0.run(CompilerInterface.scala:153)
xsbt.CachedCompiler0.run(CompilerInterface.scala:125)
xsbt.CompilerInterface.run(CompilerInterface.scala:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:248)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:122)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:95)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:91)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:186)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3$adapted(MixedAnalyzingCompiler.scala:77)
sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:215)
sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:77)
sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:146)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:343)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:343)
sbt.internal.inc.Incremental$.doCompile(Incremental.scala:120)
sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:100)
sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:180)
sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:98)
sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:102)
sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:155)
sbt.internal.inc.Incremental$.compile(Incremental.scala:92)
sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:75)
sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:348)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:301)
sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:168)
sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:248)
sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:74)
org.gradle.api.internal.tasks.scala.ZincScalaCompiler.execute(ZincScalaCompiler.java:157)
org.gradle.api.internal.tasks.scala.ZincScalaCompilerFacade.execute(ZincScalaCompilerFacade.java:47)
org.gradle.api.internal.tasks.scala.ZincScalaCompilerFacade.execute(ZincScalaCompilerFacade.java:32)
org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerWorkAction.execute(AbstractDaemonCompiler.java:135)
org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:49)
org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:43)
org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:43)
org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:87)
org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:56)
org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:138)
org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:135)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
Despite that, this error seems to be caused by trivial missing class, and it happens at a fairly late stage of compilation, when test code are being compiled.
So my question is: what does it take to make scalajs to work as a compiler plugin (WITHOUT sbt)? And what could possibly cause this error?
That error is typically symptomatic of not having scalajs-library on the compilation classpath. But I see you already added
implementation("org.scala-js:scalajs-library_${vs.scalaBinaryV}:${vs.scalaJSV}")
which, from what I understand of Gradle, should do that.
Perhaps double-check that that library indeed ends up on the compilation classpath, using whatever command Gradle offers to check that?
That said, after you're done with this, all you'll have are .sjsir files, which cannot be run or tested. You will need the Scala.js linker to process the .sjsir files on the classpath, and produce one .js file.

Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer

i have a kafkaflink job which works in intellij, on packaging with sbt i get the below message
Caused by: java.lang.ClassNotFoundException:
org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
Thanks for having a look at it
You most certainly have Kafka as provided dependency or you are not creating the fat-jar.
You need to use a plugin depending on the build tool You are using for sbt it can be sbt assembly, for maven it can be maven-shade-plugin. And then You need to have flink-kafka-connector in compile scope.

Spark submit in IntelliJ of project jar yields Class not found error

I'm doing a basic program of implementing Drools and the program runs on an application configuration but when I try to run the JAR, I face an error.
The error I get on the terminal:
`Suhita-MacBookPro:Drool-CreditScore-Sample sgoswami$ spark-submit --class main.scala.suhita.Sample --master local[*] target/DroolsMaven-1.0-SNAPSHOT.jar
java.lang.ClassNotFoundException: main.scala.suhita.Sample
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.spark.util.Utils$.classForName(Utils.scala:230)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:712)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:119)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)`
Drools-Project
>src
>main
>scala
>suhita
- Sample
- Applicant
>META-INF
-kmodule.xml
-manifest.MF
>resources.rules
-rules
This happens sometime when your classes are not loaded property. I have seen a few times recently. So there are two ways to fix this issue:
Refresh classes that may include sbt clean compile
or you can try reloading idea classes from top menu. It's very vague to say but sometimes restarting intellij also works as it reloads all the classes again.
I am sure one the method will work. Let me know if it persists.
Looking at the tree structure of your project
Drools-Project
>src
>main
>scala
>suhita
- Sample
- Applicant
You don't need to provide class name from main as main.scala.suhita.Sample
Simply use suhita.Simple for class name as
spark-submit --class suhita.Sample --master local[*] target/DroolsMaven-1.0-SNAPSHOT.jar
and it should work

Error during sbt execution: java.lang.NoClassDefFoundError: scala/StringContext

I am trying to run a play framework(2.1) application which is written in Scala but getting some error.
I need to use Play framework 2.1 only.
As per build.sbt file, I am using Scala 2.11.7.
sbt.version=0.13.8 is in project/build.properties.
I have installed Play 2.1.0 and changed my directory to application's root directory and then executed play command.
I got following error:
java.lang.NoClassDefFoundError: scala/StringContext
at sbt.CommandStrings$.<init>(CommandStrings.scala:83)
at sbt.CommandStrings$.<clinit>(CommandStrings.scala)
at sbt.BuiltinCommands$.defaults(Main.scala:202)
at sbt.xMain.run(Main.scala:29)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.ClassNotFoundException: scala.StringContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more
Error during sbt exeenter code herecution: java.lang.NoClassDefFoundError: scala/StringContext
Can someone please tell me what's wrong here?
I am completely new to scala and I just need to run this app at earliest.
I am using 64-bit Cent OS 7(in case someone wants to know about OS).
The easiest way to fix that is to use an older version of SBT. Play 2.1.5 uses 0.12.2 by default, so you can change the file project/build.properties inside your project and use that version:
sbt.version=0.12.2
You can later try newer versions of SBT if you need.
sbt.version=0.12.2 wont work with JDK8 so you might need to downgrade Java.
I used this sbt version and got the following error
eror: error while loading CharSequence, class file '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken for sbt 0.12.2

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.