Git Product home page Git Product logo

rust-java-jni's Introduction

Rust-Java-JNI

Description

This is a experimenting project on how to connect Rust and Java together using the JNI API. So that you can execute native code from Java.

This repository can be used as reference guide on how to get started.

How to reproduce

  1. Add java methods with a native identifier

  2. Run javah class-file or javah -classpath path-to-jar files class-name

    path-to-jar could also contain multiple jars (javah -classpath target/* Test)

    class-name only contains the fully qualified class name without the .class extension

  3. Call your rust methods like the ones in the generated header file

  4. Compile the rust binaries into a library

  5. Load the library into Java using System.load(LIBRARY_PATH)

  6. Now you can access the native methods

How to compile and run

  1. Rust project: cargo build > output into target/
  2. Java mvn install using Maven (included in Eclipse, IntelliJ, Netbeans)
  3. Place the library file (.dll, .so) next to the jar file java/target/
  4. Run the jar file java -jar jar-file

Other useful documents

Supported OS

  • Windows (.dll)
  • Linux (.so)
  • Mac (.so and .dylib)

Planning

  • More complex examples
  • Complete JNINativeInterface in Rust according to the jni.h file

Contribution

This project is open for contributions of any kind. If you find a better example, description, [...], just make a pull request.

This project is licensed with the unlicense, so are free to do whatever you want. Including using it in your own project without credits.

rust-java-jni's People

Contributors

games647 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.