简体   繁体   中英

Call Scala code from Java?

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.

There should be no problem in doing this.

  1. Have you verified (eg 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM