我能编写一个Java程序,调用另一种语言(Rust)的程序来进行一些计算吗?

huangapple go评论83阅读模式
英文:

Can I code a Java program that will call a program in another language (Rust) to do some calculations?

问题

我想制作一个模拟程序,但我想编写用于在Java(实际上是Kotlin,但我认为这里不相关)的JVM中显示模拟状态和用户交互(前端?)的代码,同时我想用Rust编写模拟的实际代码(后端?)。主要是因为我认为这将很有趣,我会学到一些东西。
我是否可以实现这个目标,如果可以,该如何做?可能需要注意的是两个程序之间需要交换的数据只是一个固定大小的浮点数数组。

感谢您的帮助。

英文:

I'd like to make a simulation, but I'd like to write the code to display the state of the simulation and the user interaction (frontend?) in Java (Kotlin actually, but I don't think it is relevant here) for the JVM, and I'd like to write the actual code of the simulation (backend?) in Rust. Mostly because I think it would be neat and that I would learn something.
Can I achieve this, and if yes, how? It might be relevant that the data that needs to be exchanged between the two programs is just a fixed-size array of floats.

Thank you for your help.

答案1

得分: 2

一个Rust程序会编译成本机代码(可执行文件或共享库)。要从Java中调用本机代码,您必须使用JNI:https://www.baeldung.com/jni。

您可能会发现Rust项目的jni crate很有用:https://docs.rs/jni/0.16.0/jni/。

英文:

A Rust program compiles to native code (executable or shared library). To call native code from Java you have to use JNI: https://www.baeldung.com/jni.

You may find the jni crate useful for the Rust side of the project: https://docs.rs/jni/0.16.0/jni/

huangapple
  • 本文由 发表于 2020年5月2日 18:54:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/61558209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定