1

I am using Eclipse Java and Eclipse C/C++ on OSX Yosemite to create a simple Java JNI application. Here are the steps I performed

  1. Wrote a class on Java Eclipse with native method.
  2. Using this class, created a C header file using javah executable and included the the header file in Eclipse C/C++. On building the C code, .so file is created.
  3. Then I added the path to .so file using eclipse (Run/Run Configutations/Java Application/Environment) by setting variable name as PATH and value as %PATH%/Users/XXXX/Documents/JniWorkspace/JniExampleLibrary/Debug

Here is Java code to load the C library:

public class JniExample {
   static {
        System.loadLibrary("JniExampleLibrary");
    }

    public native void callNativeMethod();
    ....
    ....

}

But still I am getting the error as shown below:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no JniExampleLibrary in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1087) at code.example.JniExample.(JniExample.java:5) at code.example.Main.main(Main.java:8)

Sampada
  • 2,931
  • 7
  • 27
  • 39
Ashutosh Pandey
  • 409
  • 1
  • 4
  • 9
  • You are setting the `PATH` environment variable. You have to set the java library path. This should help you http://stackoverflow.com/questions/661320/how-to-add-native-library-to-java-library-path-with-eclipse-launch-instead-of – xp500 Jul 14 '15 at 22:21
  • You said you're on a MAC. I'm surprised that you're getting a .so file. On mac OS I believe dynamic libraries have the .dylib extension, not the .so extension. And it may be that java expects the dynamic library to have the .jnilib extension. Regardless, I agree with @xp500 about PATH vs java.library.path. – Alain Jul 15 '15 at 14:40
  • As I said I am using Eclipse for C/C++ code and it generates .so file. Though there is an option for .a file also. .dylib file is generated through Xcode. – Ashutosh Pandey Jul 15 '15 at 15:41

0 Answers0