Unsatisfied Link Error with JNI example

A

allelopath

I am trying to do a JNI example but getting an UnsatisfiedLinkError.
I am following the example at:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
I can't follow it exactly because I'm doing it in Eclipse (Is this a bad
word in this forum?)
I created and compilled the C file per the instructions.

I add the path that the .so file is on to the java.library.path in Eclipse
by going to Run -> Run... -> Arguments -> VM Arguments and adding
-Djava.library.path=/path/to/so/file/. I added the lines to check the
library path has been set and it is what I would expect (ie it has the
path to the .so file)

What am I doing wrong?

class ReadFile
{
// native method declaration
native byte[] loadFile(String name);

// load the library
static
{
System.loadLibrary("libnativelib"); // error here
}

public static void main(String args[])
{
String libraryPath = System.getProperty("java.library.path",".");
System.out.println ("library path = " + libraryPath);

byte buf[];

// create class instance
ReadFile mappedFile=new ReadFile();

// call native method to load ReadFile.java
buf=mappedFile.loadFile("ReadFile.java");

// print contents of ReadFile.java
for(int i=0;i<buf.length;i++)
{
System.out.print((char)buf);
}
}

}
 
P

P. Barthelemy

Hi,

With Eclipse, under windows ( I guess it is the same for Linux ) :
you need to put the .dll ( or .so in your case ) in the project directory.

right-click on your project, in the 'info' tab check the 'location'.
that's were you are to put the C library.

Hope it helped...

--p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top