wpilibsuite / gradle-jni

Gradle plugin for ease of creating JNI libraries.
14 stars 5 forks source link

How to run JNI in Main class ? #19

Closed ghost closed 3 years ago

ghost commented 3 years ago

I want to run in Main class like this.

public class HelloWorld {
public native void print();

static {
System.loadLibrary("hello");
}

public static void main(String[] args) {
new HelloWorld().print();
}

}

How to use jni libs in Main class ?

ThadHouse commented 3 years ago

The code in the example project would work for doing that. Theres nothing special about a main class thats different from the example.

ghost commented 3 years ago

How to set Native library location in gradle ?

I tried this answer. But , not worked.

ThadHouse commented 3 years ago

Ah, the example does not have that code, and thats generally beyond the scope of this plugin. In essence, you have to make the directory containing your jni library be pointed to by the java.library.path variable. Then the system.load command will load it.

ghost commented 3 years ago

I want to run in Main class.

Can you give an example code ?

ThadHouse commented 3 years ago

I don't really have a standalone example right now on how to do that. I can try to throw one together if I have time in the near future.

ghost commented 3 years ago

How can I run in Main class in this project?

https://github.com/wpilibsuite/gradle-jni/blob/main/example/src/main/java/jnitest/JniFunctions.java

ThadHouse commented 3 years ago

I don't have a sample for that right now. This plugin was designed for building libraries, not applications. It can work for applications, its just not something with current documentation on how to do so.

ghost commented 3 years ago

I am not asking code . I have a doubt about calling native libraries from java with Main class in this plugin.

ghost commented 3 years ago

I think this plugin is waste.