英文:
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论