Friday, June 22, 2012

NoClassDefFoundError: scala/ScalaObject

I thought I'd start the weekend by trying to call scala code from a java project in eclipse.

I wanted to try it without having to compile the scala code to a jar first. The whole exercise was very painless.

Define some class in scala:


class Cell(val row: Int, val col: Int, val slot: Int) {

}

Then call it in your java project:


import cell.Cell;

public class JCell {
 public static void main(String[] args) {
  Cell c1 = new Cell(2, 4, 6);
  System.out.println(c1.row() + " " + c1.col() + " " + c1.slot());
}
}


The only sticking point was my build path class order needed to have the scala stuff first - which makes perfect sense when you think about it.

No comments:

Post a Comment