1834926 Members
2563 Online
110071 Solutions
New Discussion

Re: Java, JNI, aCC

 
Lee Yeow leong
Occasional Contributor

Java, JNI, aCC

I'm trying to use JNI on a HP-UX 10.2 without success. Below is the steps
that I took.

1. Wrote the Java class.

public class HelloWorld {
public native void displayHelloWorld();

public static void main(String[] args) {
System.loadLibrary("hello");
new HelloWorld().displayHelloWorld();
}
}

2. javac HelloWorld.java
3. javah -jni HelloWorld
4. Wrote the c class
#include "HelloWorld.h"
#include

JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject)
{
printf("Hello World");
return;
}

4. aCC -ext +z -c -D_HPUX -I/opt/java/include -I/opt/java/include/hp-ux hello.c

5. aCC -b -o libhello.sl hello.o -IC

6. export SHLIB_PATH=$(/bin/pwd):$SHLIB_PATH

However, when I try to run the java program using java HelloWorld, I got the
error java.lang.UnsatisfiedLinkError. Anyone knows what went wrong? TIA.
4 REPLIES 4
Xian xiang Wang
New Member

Re: Java, JNI, aCC

I guess you might need to grant executioin persmission of the share library
file via chmod a+x. Good luck.
Lee Yeow leong
Occasional Contributor

Re: Java, JNI, aCC

The permission has already been lowered. :(

Any other ideas? tia.
Yu-hsin Seah_2
Advisor

Re: Java, JNI, aCC

Can you try to see if you can run the demo JNI app in:

/opt/java/docs/hpux/JavaCallingNative

Run the "build" script and see if you still get an error similar to:

error: java.lang.UnsatisfiedLinkError: no aCCImpl in shared library path

If so, you may want to check what the version of your dld.sl (dynamic link
loader) is. Also, you may want to check what JDK version you are using. I was
testing with JDK1.17 and the "what" output of my dym link loader files is:

/usr/lib/dld.sl:
SMART_BIND
92453-07 dld dld dld.sl B.10.32 990202

/usr/lib/libdld.1:
92453-07 dld dld libdld.sl B.10.32 990202

I have PHSS_17225 dld.sl patch installed.
Lee Yeow leong
Occasional Contributor

Re: Java, JNI, aCC

Thanks. I didn't know the sample program was there. :)

I able to run it and have found the problem with my code. I have
misunderstood that the shared library should be prefixed with libc instead of
c.

Thank you! Merry Christmas!