views:

465

answers:

1

I'm using Netbeans to write Scala and Java.

Netbeans generated a .jar file for the Scala project. I tried importing that file in the Java project. But I couldn't import any class from that .jar file into my Java project.

I also tried importing scala-library.jar to the java project, and could import classes from that jar.

I want to write my library in Scala, then expose a small interface that only involves Java stuff, then write a Java wrapper so that people can use it as a Java package. Is that possible? How do I do it?

Thank you very much.

+4  A: 

There should be no problem in doing this.

  1. Have you verified (e.g. using WinZip or the jar utility) that your .jar file actually contains the relevant .class files? (use jar tvf mylib.jar to check)
  2. If you have verified that the correct .class files exist in your jar file, what is the runtime error you are seeing? Is it a NoClassDefFoundError? If so, which class cannot be found? How are you referring to the (Scala) class in your (Java) code?
oxbow_lakes
Oh thank you. It turned out this was due to my lack of knowledge in Java. I compared my package with scala-library.jar then do the following: 1. make sure all classes and sub-packages were under the same root package 2. edit the MANIFEST.MF file, with the one from scala-library.jar as a sample Then I could call my Scala classes from Java. I'm still not clear where the problem is from, but I'm in a hurry now. I'll find out later. Thank you very much :)
Po