All Projects → benanders → Rjni

benanders / Rjni

Licence: mit
Run Java code from Rust!

Programming Languages

java
68154 projects - #9 most used programming language
rust
11053 projects

Labels

Projects that are alternatives of or similar to Rjni

Javaok
必看!java后端,亮剑诛仙。java发展路线技术要点。
Stars: ✭ 867 (+1369.49%)
Mutual labels:  jvm
Javabrainmap
Java 体系涉及到的各方面知识点脑图总结,万物皆脑图。The knowledge of all aspects of the Java system is summarized in the brain map.
Stars: ✭ 33 (-44.07%)
Mutual labels:  jvm
Arquillian Extension Drone
Arquillian Drone provides a simple way to write functional tests for web apps. Drone brings the power of WebDriver into the Arquillian, and the power of Arquillian to WebDriver.
Stars: ✭ 45 (-23.73%)
Mutual labels:  jvm
Pulsar
Fibers, Channels and Actors for Clojure
Stars: ✭ 885 (+1400%)
Mutual labels:  jvm
Javacore
☕️ JavaCore 是对 Java 核心技术的经验总结。
Stars: ✭ 909 (+1440.68%)
Mutual labels:  jvm
Ineter
Fast Java library for working with IP addresses, ranges, and subnets
Stars: ✭ 39 (-33.9%)
Mutual labels:  jvm
Classpy
GUI tool for investigating Java class files
Stars: ✭ 854 (+1347.46%)
Mutual labels:  jvm
Ea Async
EA Async implements async-await methods in the JVM.
Stars: ✭ 1,085 (+1738.98%)
Mutual labels:  jvm
Blog
本仓库存放个人博客的 markdown 源文件
Stars: ✭ 951 (+1511.86%)
Mutual labels:  jvm
Kotlin Boot Camp
kotlin course materials
Stars: ✭ 43 (-27.12%)
Mutual labels:  jvm
Fake Jni
An implementation of the JNI and JVMTI with support for direct interaction between natively registered classes and JVM objects.
Stars: ✭ 20 (-66.1%)
Mutual labels:  jvm
Docker Discovery Registrator Consul
Service discovery library for JVM based applications running in Docker containers that use the Registrator service registry bridge with Consul as a backend
Stars: ✭ 21 (-64.41%)
Mutual labels:  jvm
Flatjson
A fast JSON parser (and builder)
Stars: ✭ 39 (-33.9%)
Mutual labels:  jvm
Mbassador
Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven
Stars: ✭ 877 (+1386.44%)
Mutual labels:  jvm
Graceful Shutdown Spring Boot
Graceful Shutdown with Spring Boot (Demo)
Stars: ✭ 51 (-13.56%)
Mutual labels:  jvm
Metrics Jvm Extras
A set of additional metrics complementing Dropwizards metrics-jvm.
Stars: ✭ 10 (-83.05%)
Mutual labels:  jvm
Cockburst
一个高性能,可靠,异步的本地持久化队列实现;重启JVM、重启服务器、或者强制KILL进程时,队列里的数据不丢失;
Stars: ✭ 33 (-44.07%)
Mutual labels:  jvm
Play Scala Slick Example
Example Play Scala project with Slick
Stars: ✭ 59 (+0%)
Mutual labels:  jvm
Staged Streams.scala
Stars: ✭ 55 (-6.78%)
Mutual labels:  jvm
J J Jvm
JVM bytecode interpreter written in Java
Stars: ✭ 40 (-32.2%)
Mutual labels:  jvm

Java Native Interface Bindings for Rust

This library provides complete FFI bindings to the Java Native Interface, as well as a safe and intuitive wrapper around most these bindings (lacking array support for now).

Features include:

  • Creating and configuring an instance of a Java Virtual Machine
  • Loading classes
  • Calling static methods on classes
  • Setting and retrieving public static fields on classes
  • Instantiating objects from a class
  • Calling methods on objects
  • Setting and retrieving public fields on objects
  • Using all primitive Java types and other Java objects as arguments and return values (no support for arrays yet)

Documentation

Documentation can be found here.

Usage

First you'll need to compile your Java source code, either as separate .class files, or package them together as a .jar archive.

You need to make sure you target the Java compiler to the JVM version you plan to use. This is done through the -target and -source command line arguments to javac.

For example, if you have a /path/to/project/com/me/Test.java file (ie. the class com.me.Test) and you intend to target the 1.6 JVM:

$ javac -target 1.6 -source 1.6 /path/to/project/com/me/Test.java

This will create a /path/to/project/com/me/Test.class file.

Then when you create the JVM in Rust, you need to add /path/to/project (ie. the directory containing the root of your Java code) to the classpath, and specify the correct JVM version:

use rjni::{Jvm, Version, Classpath, Options};

fn main() {
	// Create a custom classpath, pointing to the directory containing the root
	// of your Java code
	let mut classpath = Classpath::new();
	classpath.add(&Path::new("/path/to/project"));

	// Create a series of configuration options for the JVM, specifying the
	// version of the JVM we want to use (1.6), and our custom classpath
	let mut options = Options::new();
	options.version(Version::V16);
	options.classpath(classpath);

	// Create the JVM with these options
	let jvm = Jvm::new(options).unwrap();

	// Get the `com.me.Test` class using the JVM
	let class = jvm.class("com/me/Test").unwrap();

	// ...
}

See the examples folder for more example code on how to call static methods on classes, instantiate objects, call methods on objects, and access object fields.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].