Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNI Program RunTime Exceptions

 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai friends
I am trying to call the Functionality from C program to Java Program using JNI
The C program is like
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}

Java Program is
class HelloWorld
{
public native void displayHelloWorld();

static
{
System.loadLibrary("hello");
}
public static void main(String[] args)
{
new HelloWorld().displayHelloWorld();
}
}
I compiled java program using this
javac HelloWorld.java
and i made it as .h file using
javah -jni HelloWorld
Everything is fine but when i am trying to run the java program like this
java HelloWorld
It is saying exception
Exception is
java.lang.UnsatisfiedLinkError: no hello in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at
at java.lang.Thread.init(Thread.java)

What shall i do to get the output
Please give me some suggestions
Thanksinadvance
Yours
Rajesh Kumar
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the line you're using to compile the code? What directory are you putting the .dll/.so file in?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Michael Ernest
Thankyou VeryMuch
The problem is that what u expressed.
Now I kept .dll file in the directory where class files and .h files stored.
now it is working fine.
Thankyou VeryMuch
Yours
Rajesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic