scalamap-force

Importing Scala .class files into MapForce


Altova Mapforce allows user defined functions to be imported from Java .class files. Since Scala also compiles to Java .class files, I figured I could use them interchangeably. So I wrote some test objects and found I could import the .class files successfully but using some functions would fail always with

java.lang.NoclassDefFoundError: scala/something

For example, if compile the following file with scalac. I can import Pass.class and Fail.class with no issues

object Pass {
  def echo(s: String): String = s // no errors
}
object Fail {
  def greet(name: String): String = {
    // java.lang.NoClassDefFoundError: scala/collection/mutable/StringBuilder
    "Hello, " + name 
  }  
}

Using Pass.echo works but Fail.greet raises the error, java.lang.NoClassDefFoundError: scala/collection/mutable/StringBuilder.

My understanding is Mapforce is searching the Java libraries for Scala classes. If that is correct then how can I tell MapForce to include Scala libraries? Otherwise, what is the cause?


Solution

  • I wasn't able to pass the scala library to the applications classpath directly as Lattyware suggested but adding it to the global classpath allowed MapForce to use scala classes in the application.

    PS C:\> echo $env:CLASSPATH
    .;C:\Program Files\scala\lib;
    

    I haven't tested how well that works with generating Java code.