NoClassDefFoundError: scala / ScalaObject in a mixed scala / Java project

Reference Information. I am a C # developer, but my next project should be on the JVM. I researched Scala, and I think it allows me to do what I can in C # (Lambdas, supposed types, functional style, etc.). I would classify myself as an aspiring Java developer ... especially when it comes to using an IDE, etc.

I have a Scala project that seems to work ... I made a Java project and referenced the Scala project. The editor seems to know about the classes in the Scala project (typeahead, etc.)

When I try to start a Java project, I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at learning_scala.java.Main.main(Main.java:12) Caused by: java.lang.ClassNotFoundException: scala.ScalaObject at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) 

Obviously, something went wrong in the Java / Scala compilation, but I have no idea how to resolve it (my lack of Java experience is the main culprit here)

I use Eclipse with the official Scala plugin ... all of which are updated 2-3 days ago.

thanks

+6
source share
1 answer

You need to add the scala -library.jar library to your classpath. You can do this in several different ways, but the easiest is to copy the file to your project (drag it into your eclipse package explorer). Then right-click on the file and select the add to build command. This adds a scala jar to your class path. This should solve the problem.

+8
source

Source: https://habr.com/ru/post/899383/


All Articles