I am trying to load the JNI library and run the below program but I am getting the below error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no JNIDemo
in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at demo.JNIWrapper.<clinit>(JNIWrapper.java:10)
Below are my Java,C,command
Step1:Java Code :Present in a Eclipse Project at Path (/documents/JNIDemoProject/src/main/java/demo)
package demo;
public class JNIWrapper {
static{
//System.load("/home/arpit/Documents/JNI/libJNIDemo.so");
System.loadLibrary("JNIDemo");
}
public native int multiply(int a,int b);
public static void main(String args[]){
try{
JNIWrapper jni=new JNIWrapper();
int result=jni.multiply(7, 8);
System.out.println("Result is "+result);
}catch(Exception e){
e.printStackTrace();
}
}
}
Step 2:A .h file named demo_JNIWrapper was created (Note name is demo_JNIWrapper as I had to run the javah command from /documents/JNIDemoProject/src/main/java)
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class demo_JNIWrapper */
#ifndef _Included_demo_JNIWrapper
#define _Included_demo_JNIWrapper
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: demo_JNIWrapper
* Method: multiply
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_demo_JNIWrapper_multiply
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
Step 3:
I create a C file
#include<stdio.h>
#include <jni.h>
#include "demo_JNIWrapper.h"
JNIEXPORT jint JNICALL Java_demo_JNIWrapper_multiply
(JNIEnv *env, jobject jobj, jint a, jint b){
int result=a*b;
return result;
}
Step 4:
I create the lib file named libJNIDemo.so
Step 5:
All the three files(libJNIDemo.so,demo_JNIWrapper.h,HelloJNI.c) are located at the folder /users/documents/JNI
Step 6:
I export it into lib path
export LD_LIBRARY_PATH="/users/documents/JNI"
Step7:
When I run the java program it gives me the above error .
POINT TO NOTE:
My program runs fine when I load the libJniDemo.so file directly with the path
static{
System.load("/users/documents/JNI/libJNIDemo.so");
//System.loadLibrary("JNIDemo");
}
Can anyone please suggest
Java uses dlopen() on Linux (and other Unix or Unix-like operating systems) to find native libraries. From the Linux dlopen() man page:
If filename is NULL, then the returned handle is for the main
program. If filename contains a slash ("/"), then it is interpreted
as a (relative or absolute) pathname. Otherwise, the dynamic linker
searches for the object as follows (see ld.so(8) for further
details):
o (ELF only) If the executable file for the calling program
contains a DT_RPATH tag, and does not contain a DT_RUNPATH tag,
then the directories listed in the DT_RPATH tag are searched.
o If, at the time that the program was started, the environment
variable LD_LIBRARY_PATH was defined to contain a colon-separated
list of directories, then these are searched. (As a security
measure, this variable is ignored for set-user-ID and set-group-
ID programs.)
o (ELF only) If the executable file for the calling program
contains a DT_RUNPATH tag, then the directories listed in that
tag are searched.
o The cache file /etc/ld.so.cache (maintained by ldconfig(8)) is
checked to see whether it contains an entry for filename.
o The directories /lib and /usr/lib are searched (in that order).
If you can, run your Java process under strace, trace open calls, and see where the JVM is looking for your native library, and exactly what it's looking for.
Given knowing how dlopen() work, and the information from strace, you should be able to determine exactly what's happening.
One thing to be aware of: you may be creating a 64-bit native library but running a 32-bit JVM.
Related
I have found other posts of people having this exact error, but not one thus far has had a solution that worked for me. For reference, here are the things I have found:
https://community.oracle.com/tech/developers/discussion/2233828/jni-link-error-a-dynamic-link-library-dll-initialization-routine-failed
JNI UnsatisfiedLinkError: A dynamic link library (DLL) initialization routine failed
https://www.debugcn.com/en/article/5175409.html
https://coderanch.com/t/132356/engineering/java-lang-UnsatisfiedLinkError
Either their solution was not relevant to my particular scenario, or it did not fix the issue for me.
Everything is being compiled on the command line with a Windows 10 computer and using GCC (gcc-5.1.0-tdm64-1-c++) for compiling the C++ portions into a .dll, and JDK 15.0.1's javac tool. There are three relevant files here, one being the header file derived from the java file.
Main.java:
public class Main {
static {
System.load("C:\\Users\\17659\\Documents\\Programming\\C++ & Java - JNI Tests\\library.dll");
//System.loadLibrary("library");
}
public static void main(String[] args) {
new Main().outputText();
}
private native void outputText();
}
Main.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Main */
#ifndef _Included_Main
#define _Included_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Main
* Method: outputText
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Main_outputText
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
Library.cpp:
#include <iostream>
#include "Main.h"
JNIEXPORT void JNICALL Java_Main_outputText(JNIEnv * a, jobject b)
{
std::cout << "testing";
}
They are contained all within the folder with the absolute path of C:\Users\17659\Documents\Programming\C++ & Java - JNI Tests. With a command prompt set to that as the current directory, I run the following commands in order:
g++ -c -o Library.o -I"C:\Users\17659\Documents\jdk-15.0.1\include" -I"C:\Users\17659\Documents\jdk-15.0.1\include\win32" Library.cpp
g++ -shared -o library.dll Library.o
javac Main.java
java Main
Despite the multiple things I have tried, I always get this same error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\17659\Documents\Programming\C++ & Java - JNI Tests\library.dll: A dynamic link library (DLL) initialization routine failed
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2407)
at java.base/java.lang.Runtime.load0(Runtime.java:747)
at java.base/java.lang.System.load(System.java:1857)
at Main.<clinit>(Main.java:3)
I have used nm on the resulting .dll to make sure the name of the function is correct, and it does seem to be exactly as it should.
The entire point of this little project of mine is to figure out how JNI works, since I have a plan to write a small portion of a program in C++. The rest of the program though would work best in Java (for me). I do not know what I need to do to get this program to work, I have spent approximately 2 hours of googling and fiddling attempting to get it to function. This is on a 64-bit OS. How can I make this program run and print out the very little amount of text I would like it to print out?
Update: As per #JornVernee removing the line #include <iostream> and replacing the std::cout with a printf() to write to the console did actually work. So my question now becomes this: why does including a standard C++ header cause an error?
Well, #JornVernee effectively nailed the issue right on the head. It was a mismatch between the standard library I had for C++ and the one being loaded. I changed the version of GCC I was using to a more up-to-date version, recompiled the entire project, and the program works now.
I'm trying to call a c function from Java.
When loading the library (in Test.java) 2 things happen randomly:
"Load Lib" gets printed, and the jvm just exits without any errors
"Load Lib" gets printed, and the jvm gets stuck in a loop
The weird thing is that 'sometimes' "Lib loaded" gets printed too. Which means the library got loaded...
My question is that how can I fix this? The real problem is that I don't know what I'm doing wrong.
Dll compilation steps:
gcc -fpic -I "C:\Program Files\Java\jdk-15\include" -I "C:\Program Files\Java\jdk-15\include\win32" -c BindLib.c BindLib.h
gcc -fpic -s -shared -o BindLib.dll BindLib.o
System info:
Windows 10 64 bit, version 1909
Java 15
Main file:
package degubi;
public final class Main {
public static void main(String[] args) {
Test.enable();
}
}
Library file:
package degubi;
public class Test {
static {
System.out.println("Load lib");
System.loadLibrary("BindLib");
System.out.println("Lib loaded");
}
public static native void enable();
}
Source file:
#include "windows.h"
#include "BindLib.h"
JNIEXPORT void JNICALL Java_degubi_Test_enable(JNIEnv* env, jclass clazz) {
}
Header file:
#define __int64 long long
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class degubi_Test */
#ifndef _Included_degubi_Test
#define _Included_degubi_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: degubi_Test
* Method: enable
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_degubi_Test_enable(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
Which shell and C compiler were you using?
The problem might come from the incompatible between C compiler & the shell environment.
For example, if you use Cygwin compiler to compile the DLL, then execute the binary on Windows CMD, the program might not work (dependencies on cygwin.dll).
I ended up creating a project in Visual Studio and building it from there... worked perfectly. Still don't know what caused the issue.
I'm trying to get a small/sample Java application, which invokes native C++ code using JNI calls, running on Linux.
I use Eclipse to build, configure the environment and run the application.
I have divided the "overall" project in 2 separate Eclipse projects: 1 Java project and 1 C++ project, containing the native code.
Eclipse project view
The Java part consists of:
1: a "main" class, from which an "adapter" class is invoked to load the .so library and call the native interface/C++ methods
2: an "adapter" class, containing the native method declarations
public class Java_Main_For_So_Kickoff {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello from Java main!");
Native_Cpp_Adapter adapter = new Native_Cpp_Adapter();
adapter.locSetProperty();
adapter.locLoadLib();
adapter.sayHello();
adapter.test_Kickoff_So_For_Print();
}
}
public class Native_Cpp_Adapter {
public native void test_Kickoff_So_For_Print();
public void locSetProperty() {
"/home/adminuser/workspace_Unit_Test_Java_Cpp/Unit_Test_Cpp/Debug");
String libPathProp = System.getProperty("java.library.path");
System.out.println("lib path set:" + libPathProp);
}
public void locLoadLib() {
System.setProperty("java.library.path",
"//home//adminuser//workspace_Unit_Test_Java_Cpp//Unit_Test_Cpp//Debug//");
String libPathProp = System.getProperty("java.library.path");
String soLibName = "libUnit_Test_Cpp.so";
String soLibWithPath = libPathProp.concat(soLibName);
System.out.println("lib path set for loading:" + libPathProp);
System.load(soLibWithPath);
System.out.println("library loaded");
}
public void sayHello() {
System.out.println("Hello from JNI Adapter (Java part)");
}
}
The C++ part consists of:
1: a *.h file, generated with javah, containing the native method definition
2: a *.cpp file, containing the C++ implementation of the native methods
Both very rudimentary, only meant to sanity-test the JNI environment setup. Added this, omitted that in the original post for this issue.
.h file: Native_Cpp_adapter.h
/*
* Native_Cpp_Adapter.h
*
* Created on: Aug 23, 2017
* Author: adminuser
*/
#ifndef SRC_NATIVE_CPP_ADAPTER_H_
#define SRC_NATIVE_CPP_ADAPTER_H_
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Native_Cpp_Adapter */
#ifndef _Included_Native_Cpp_Adapter
#define _Included_Native_Cpp_Adapter
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_Native_Cpp_Adapter_test_Kickoff_So_For_Print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#endif /* SRC_NATIVE_CPP_ADAPTER_H_ */
.cpp file: Native_Cpp_Adapter.cpp
#include "jni.h"
#include <iostream>
using namespace std;
JNIEXPORT void JNICALL Java_Native_Cpp_Adapter_test_Kickoff_So_For_Print
(JNIEnv *, jobject)
{
cout << "Correct kickoff of Native JNI method nr. 1";
return;
}
From the C++ project an .so is built, including jni.h and jni_md.h. for the Java project, the resulting .so is included as external library in the Java build path and added as VM argument "java.library.path" in the run configuration (for the applicable Java project/main class).
First, the .so is built from the C++ project: this results in an .so binary in the C++ project folder within the common workspace.
The the Java build is performed. Thereafter the Java program is run invoking the project's main class.
Result: the .so appears to be loaded, but thereafter the process is aborted with an (very persistent) "UnsatisfiedLinkError".
For what I understand, this error is thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
This sounds like the native method definition (C++ side) is not compliant with the native method declaration on the Java-side.
But the C++ definitions are as far as I see/know entirely compliant with the native method declaration in Java, and with the applicable native method naming conventions.
For me, it appears that all building/configuration options are exhausted - does anyone have a suggestion what might be the cause, and to solve this?
It looks like name of your native method is not valid. Make sure to properly escape _ . _ is used to separate packages in native methods. You need to follow naming convention:
https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#resolving_native_method_names
If you have "_" in method name, you need to escape it with "_1" in native code.
Example. For method in Java:
public static native void display_Message();
you need:
JNIEXPORT void JNICALL Java_recipeNo001_HelloWorld_display_1Message
(JNIEnv *, jclass);
Note "_1" that is between "display" and "Message".
Source taken (and slightly modified) from here: http://jnicookbook.owsiak.org/recipe-No-001/
Update
Where should you pay attention:
If everything else fails, make sure to set LD_LIBRARY_PATH before running Eclipse. This will give you some insight whether Eclipse plays nasty or something else is broken
Make sure to pass java.library.path using "-D" while starting your code. You can set it in Debug configuration as JVM arguments
Sometimes, it might be tricky, and it may turn out that your lib doesn't contain symbol at all. You can check it using nm
nm libSomeLibFile.so
You can also set native code location inside project's Properties configuration in Eclipse
Update. I have slightly simplified your code to make it easier to check what is wrong. I suggest you to remove "_" from class names as well as they are again mixed up in native code.
Take a look here:
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello from Java main!");
NativeCppAdapter adapter = new NativeCppAdapter();
adapter.locLoadLib();
adapter.testKickoffSoForPrint();
}
}
Native Adapter class
public class NativeCppAdapter {
public native void testKickoffSoForPrint();
public void locLoadLib() {
String soLibName = "/tmp/libNativeCppAdapter.so";
System.load(soLibName);
}
}
C++ code (pay attention to C export - it has impact on function name !)
#include "jni.h"
#include <iostream>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: NativeCppAdapter
* Method: testKickoffSoForPrint
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_NativeCppAdapter_testKickoffSoForPrint
(JNIEnv *, jobject) {
cout << "Correct kickoff of Native JNI method nr. 1";
return;
}
#ifdef __cplusplus
}
#endif
Compile code and Java
> javac *.java
> c++ -g -shared -fpic -I${JAVA_HOME}/include \
-I${JAVA_HOME}/include/darwin \
NativeCppAdapter.cpp \
-o /tmp/libNativeCppAdapter.so
> java -cp . Main
Hello from Java main!
Correct kickoff of Native JNI method nr. 1
Just few more remarks
If you compile code without
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
your symbols inside library will be incorrect (not what JVM expects).
Another thing is. If you use "loadLibrary" you have to make sure that file name is in the form: libSomeName.so and you load file via System.loadLibrary("SomeName"); - and you have to make sure that either java.library.path or LD_LIBRARY_PATH point to the file. If you use System.load, on the other hand, you don't have to make any assumptions regarding name. Just make sure you provide full path to file. For example: /tmp/someFileWithMyLib
I'm running Netbeans on 64-bit Windows 8, with JDK 1.7_25 (64-bit), following the instructions for the Beginning JNI with NetBeans (https://netbeans.org/kb/docs/cnd/beginning-jni-linux.html)
The instructions are for linux, but the principle is the same for Windows I believe (generating a .dll file instead of .so, using win32 includes in the JDK, etc)
I have Cygwin64 installed as well as Cygwin32. Using Cygwin64, I'm able to generate a 64-bit DLL from my C/C++ Dynamic Library project. However, when I call System.load("path/to/JNITest.dll"), I get:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Andrew\Documents\NetBeansProjects\JNITestLib\dist\JNITest.dll: %1 is not a valid Win32 application
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1843)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1061)
at jnitest.JNITest.main(JNITest.java:8)
Java Result: 1
From what I gather, this is most often the case when loading a 64-bit application on a 32-bit virtual machine, but my netbeans.conf is pointing to a 64-bit JVM.
Additionally, when I use the 32-bit version of Cygwin to compile things and run, I get
Can't load IA 32-bit .dll on a AMD 64-bit platform
I'm pretty sure I'm correctly generating the DLL file, it's just a simple HelloWorld printf to follow the JNI tutorial. I'm very new to JNI and C, so I'm not really sure where to start debugging. The best I've done is tried both 32 and 64-bit DLLs, and I've made sure my C compiler (Cygwin) is 64-bit, and my JVM is too.
I'd appreciate any insight!
Edit: Here are the included files
=== Java (JNITest.java) ===
package jnitest;
public class JNITest {
public static void main(String[] args) {
System.out.println("JVM: " + System.getProperty("sun.arch.data.model"));
System.load("C:\\Users\\Andrew\\Documents\\NetBeansProjects\\JNITestLib\\dist\\JNITest.dll");
new JNITest().doHello();
}
public native void doHello();
}
=== Generated javah header (jnitest_JNITest.h) ===
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jnitest_JNITest */
#ifndef _Included_jnitest_JNITest
#define _Included_jnitest_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: jnitest_JNITest
* Method: doHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_jnitest_JNITest_doHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
=== C (JNITest.c) ===
#include <jni.h>
#include "jnitest_JNITest.h"
JNIEXPORT void JNICALL Java_jnidemojava_Main_nativePrint
(JNIEnv *env, jobject obj)
{
printf("\nHello World from C\n");
}
Edit:
The problem seems to be with the DLL, since I can load other 64-bit DLLs just fine. I thought that Cygwin might be the problem, so I changed my compiler to MinGW-w64. It compiled fine, and the library loads, but now I get a new exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: jnitest.JNITest.doHello()V
at jnitest.JNITest.doHello(Native Method)
at jnitest.JNITest.main(JNITest.java:10)
Java Result: 1
Some more digging found that the error is thrown when ClassLoader reads libs.size() here:
// Invoked in the VM class linking code.
static long findNative(ClassLoader loader, String name) {
Vector<NativeLibrary> libs =
loader != null ? loader.nativeLibraries : systemNativeLibraries;
synchronized (libs) {
int size = libs.size();
for (int i = 0; i < size; i++) {
NativeLibrary lib = libs.elementAt(i);
long entry = lib.find(name);
if (entry != 0)
return entry;
}
}
return 0;
}
Edit: ANSWERS!
Finally figured it out.
Firstly, something was wrong with Cygwin64. Using a different 64-bit C compiler got rid of the not a valid win32 application error.
Secondly, my JNITest.c file's method signature was incorrect. It should have been:
Java_jnitest_JNITest_doHello
Instead of
Java_jnitest_Main_doHello
After changing that, it works!
(though I can't answer my own question for another 6 hours... so dum de dum)
Finally figured it out.
Firstly, something was wrong with Cygwin64. Using a different 64-bit C compiler got rid of the not a valid win32 application error.
Secondly, my JNITest.c file's method signature was incorrect. It should have been:
Java_jnitest_JNITest_doHello
Instead of
Java_jnitest_Main_doHello
After changing that, it works!
I am trying to call a simple native method in Java from C++, to achieve this I do the following:
Create a simple class as shown below:
public class HelloNative{
public native void printString(String str);
static{
System.out.println("Current Directory is: " + System.getProperty("user.dir"));
System.load(System.getProperty("user.dir") + "/libhellonative.so");
}
public static void main(String[] args){
System.out.println("Calling Native Libraray (libhellonative.so) method printString");
new HelloNative().printString("Message from Java to C");
}
}
Create .h file for the native method using javah -jni which create the following declaration:
JNIEXPORT void JNICALL Java_HelloNative_printString(JNIEnv *, jobject, jstring);
Implement the native function in .cpp file as:
JNIEXPORT void JNICALL Java_HelloNative_printString(JNIEnv* jni_env, jobject java_obj, jstring msg){
printf("inside native method\n");
jboolean iscopy;
const char *message = (jni_env)->GetStringUTFChars( msg, &iscopy);
printf("%s", message);
}
And finally create the .so file using:
g++ HelloNative.cpp -o libhellonative.so -shared -Wl,-soname,libhellonative.so -static -lc -I /usr/lib/jvm/java-6-sun-1.6.0.26/include -I /usr/lib/jvm/java-6-sun-1.6.0.26/include/linux
But when I compile and run the .java file it's giving me Runtime Exception:
Current Directory is: /home/gmuhammad/Projects/test
Calling Native Libraray (libhellonative.so) method printString
Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloNative.printString(Ljava/lang/String;)V
at HelloNative.printString(Native Method)
at HelloNative.main(HelloNative.java:16)
Ok, I got this to work. It has nothing to do with loading the library, but with actually calling the method from that library.
I created .java, .h and .cpp files by copy/paste from your question and ran them (I had to add #include <jni.h> in the .cpp file) - and got exactly the same error as you did.
Then I edited the .cpp file to include the generated .h file. Also, as maba indicated in his answer, you need to call (jni_env)->ReleaseStringUTFChars(msg, message); to release the object. My full .cpp file now looks like this:
#include "HelloNative.h"
JNIEXPORT void JNICALL Java_HelloNative_printString(JNIEnv* jni_env, jobject java_obj, jstring msg){
printf("inside native method\n");
jboolean iscopy;
const char *message = (jni_env)->GetStringUTFChars( msg, &iscopy);
printf("%s", message);
(jni_env)->ReleaseStringUTFChars(msg, message);
}
I re-compiled the library, ran the java code - and voila! everything works. This way, it works regardless of which way you load the library, with load or loadLibrary.
Give it a try.
I recommend to load the library slightly differently.
Place your libmynative.so into whatever directory you like.
Add that directory to LD_LIBRARY_PATH variable.
In your java code, change System.load call to be System.loadLibrary("mynative") (note the lack of full path, prefix lib and extension .so)
Run your java code.
Have a look here for more details: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
It is totally OK to use the System.load() but you will have to be sure that your shared libraries really are where you say they should be.
Current Directory is: /home/gmuhammad/Projects/test
Your code is trying to access the shared library in that directory. Are you sure that the libhellonative.so is there?
Then you can also use the System.mapLibraryName("hellonative") to get the name of the shared library for the current platform. That makes it more platform independent. The call will give you libhellonative.so on linux and hellonative.dll on windows.
Also you must call (jni_env)->GetReleaseUTFChars(msg, message); to release the objects.