[英]Call Scala code from Java?
I'm using Netbeans to write Scala and Java. 我正在使用Netbeans编写Scala和Java。
Netbeans generated a .jar file for the Scala project. Netbeans为Scala项目生成了一个.jar文件。 I tried importing that file in the Java project.
我尝试在Java项目中导入该文件。 But I couldn't import any class from that .jar file into my Java project.
但我无法将该.jar文件中的任何类导入到我的Java项目中。
I also tried importing scala-library.jar to the java project, and could import classes from that jar. 我也尝试将scala-library.jar导入java项目,并可以从该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. 我想在Scala中编写我的库,然后公开一个只涉及Java东西的小接口,然后编写一个Java包装器,以便人们可以将它用作Java包。 Is that possible?
那可能吗? How do I do it?
我该怎么做?
Thank you very much. 非常感谢你。
There should be no problem in doing this. 这样做应该没有问题。
jar
utility) that your .jar
file actually contains the relevant .class
files? jar
实用程序)您的.jar
文件实际上包含相关的.class
文件? (use jar tvf mylib.jar
to check) jar tvf mylib.jar
来检查) .class
files exist in your jar
file, what is the runtime error you are seeing? jar
文件中存在正确的.class
文件,那么您看到的运行时错误是什么? Is it a NoClassDefFoundError
? NoClassDefFoundError
吗? If so, which class
cannot be found? class
找不到? How are you referring to the (Scala) class in your (Java) code?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.