Got NoSuchMethodError when calling scala library from Java

384 Views Asked by At

In my library written in Scala, I defined a class

class RouterRule(val rule: String) {}

it works fine when I call it from scala (in same library or from another scala project), but got a NoSuchMethodError when calling it from Java in another project:

aa$ java -classpath '*' org.jinou.http.SimpleHttpJava
Exception in thread "main" java.lang.NoSuchMethodError: org.jinou.http.RouterRule.<init>(Ljava/lang/String;)V
    at org.jinou.http.MySimpleHandler$$anonfun$org$jinou$http$MySimpleHandler$$getHttpHandlerMethods$3.apply(SimpleHttpServer.scala:98)
    at org.jinou.http.MySimpleHandler$$anonfun$org$jinou$http$MySimpleHandler$$getHttpHandlerMethods$3.apply(SimpleHttpServer.scala:96)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)

I checked the class via javap, I can find the method was generated:

javap -classpath simple-http-1.0.jar org.jinou.http.RouterRule
Compiled from "RouterRule.scala"
public class org.jinou.http.RouterRule extends java.lang.Object implements scala.ScalaObject{
     public static final scala.collection.Seq convert(scala.collection.Seq);
     public static final scala.Option check(scala.collection.Seq, java.lang.String);
     public static final scala.util.matching.Regex dynamic();
     public java.lang.String rule();
     public scala.Option checkUrl(java.lang.String);
     public org.jinou.http.RouterRule(java.lang.String);
}

Both projects are built by maven. Scala version 2.9.1, Java: 1.6.0_51

Is this a compiler bug?

[Updated]: found the issue: there is same class RouterRule in another library with different constructor. Java runtime used a wrong class. It worked after I deleted that class.

0

There are 0 best solutions below