Why do I get `java.lang.NoClassDefFoundError: scala/Function1` when I run my code in ScalaIDE?

43,497

Solution 1

adding the Scala dependency to the maven build can fix the issue :

<dependency>
    <groupId>org.scala-lang</groupId>
    <artifactId>scala-library</artifactId>
    <version>2.10.3</version>
</dependency>

Solution 2

As for me, in the configuration of "Run/Debug configurations" [idealJ]

remember to choose the "Include dependencies with "Provided" scope"

Share:
43,497
blue-sky
Author by

blue-sky

scala :: java

Updated on February 23, 2020

Comments

  • blue-sky
    blue-sky about 4 years

    Here is a simple test I'm using to invoke a Scala method from Java:

    public static void main(String args[]) {
      java.util.Map<String, java.util.List<String>> rec = news.recommend.DriverObj.runTest();     
      System.out.println(rec.toString());
    }
    

    Here is the definition of the Scala method:

    def runTest: java.util.Map[String, java.util.List[String]] = {
      new java.util.HashMap[String, java.util.List[String]]
    }
    

    But it throws an error:

    Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function1
        at news.recommend.DriverObj.runTest(DriverObj.scala)
    

    What should I do to make this running smoothly?

    Update : I'm running it via Eclipse and my build path contains :

    enter image description here

    So Scala library should be found ?

  • febot
    febot about 6 years
    Didn't help for me. I am running through Gatling. Looks like Gatling controls its classpath differently.
  • lallantop
    lallantop over 4 years
    Worked for me. Thanks!
  • lallantop
    lallantop over 4 years
    I already had this dependency listed and was still having the issue. The solution from @Kuang Wenyi worked for me.
  • Filip
    Filip almost 3 years
    Worked for me also, but why?
  • Kuang Wenyi
    Kuang Wenyi almost 3 years
    @Filip I believe there is some issue between the IdeaJ and maven.