从 Java 调用 Scala 代码?

发布于 2024-08-03 06:32:26 字数 301 浏览 3 评论 0原文

我正在使用 Netbeans 编写 Scala 和 Java。

Netbeans 为 Scala 项目生成了一个 .jar 文件。我尝试在 Java 项目中导入该文件。但我无法将该 .jar 文件中的任何类导入到我的 Java 项目中。

我还尝试将 scala-library.jar 导入到 java 项目中,并且可以从该 jar 导入类。

我想用 Scala 编写我的库,然后公开一个仅涉及 Java 内容的小接口,然后编写一个 Java 包装器,以便人们可以将其用作 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昵称有卵用 2024-08-10 06:32:26

这样做应该没有问题。

  1. 您是否已验证(例如使用 WinZip 或 jar 实用程序)您的 .jar 文件实际上包含相关的 .class 文件? (使用 jar tvf mylib.jar 检查)
  2. 如果您已验证 jar 文件中存在正确的 .class 文件,那么您看到运行时错误吗?是NoClassDefFoundError吗?如果是这样,哪个找不到?您如何在(Java)代码中引用(Scala)类?

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?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文