MCPcopy Index your code
hub / github.com/GreptimeTeam/rust-java-demo

github.com/GreptimeTeam/rust-java-demo @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
49 symbols 83 edges 9 files 10 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RustJavaDemo

Introduction

This is a demo project that shows the interop between Rust and Java, through the JNI.

It demonstrates the following usages:

  1. Assemble a single unified JAR that can run in multi platforms (aarch64 MacOS or x86 Linux etc), so that you don't need to manage lots of platform specific artifacts. And this is done in a convenient Github Action.
  2. Basic function calls from Java to Rust defined native methods, and from Rust to the Java side.
  3. Async method invocations in Rust, which are called from sync Rust functions that are provided for the JNI.
  4. Logging practice that unifies Rust logs and Java logs.
  5. Rust errors throw as RuntimeExceptions in Java.

All these features are very needed in any serious business projects. You can also use this demo as a template to start developing your own project.

Build

Clone this repo, and simply run mvn package in the project root.

The prerequisites are Java version 17 or above, and Rust toolchain.

Example

You can find an example in example/src/RustJavaDemoExample.java. It fetches the web page content from the URL you provided as a cli argument. Once you build this project, you can run this example like this:

cd example/target
java -cp ./rust-java-demo-example.jar RustJavaDemoExample "http://www.greptime.com"

It will print the content of our website "http://www.greptime.com".

Core symbols most depended-on inside this repo

get
called by 5
core/src/main/java/io/greptime/demo/utils/AsyncRegistry.java
jni_env
called by 2
core/src/main/rust/demo/src/lib.rs
getLogger
called by 2
core/src/main/java/io/greptime/demo/utils/Logger.java
info
called by 2
core/src/main/java/io/greptime/demo/utils/Logger.java
find_method
called by 1
core/src/main/rust/demo/src/logger.rs
with_logger
called by 1
core/src/main/rust/demo/src/logger.rs
init_logger
called by 1
core/src/main/rust/demo/src/logger.rs
enabled
called by 1
core/src/main/rust/demo/src/logger.rs

Shape

Method 23
Function 17
Class 8
Enum 1

Languages

Rust63%
Java37%

Modules by API surface

core/src/main/rust/demo/src/lib.rs12 symbols
core/src/main/rust/demo/src/logger.rs11 symbols
core/src/main/java/io/greptime/demo/utils/Logger.java8 symbols
core/src/main/rust/demo/src/method_invoker.rs5 symbols
core/src/main/java/io/greptime/demo/utils/AsyncRegistry.java4 symbols
core/src/main/java/io/greptime/demo/RustJavaDemo.java4 symbols
example/src/main/java/RustJavaDemoExample.java2 symbols
core/src/main/rust/demo/src/method_invoker/test.rs2 symbols
core/src/main/rust/demo/src/error.rs1 symbols

For agents

$ claude mcp add rust-java-demo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact