JNI classloading in WLS8.1

Hi,
I have a web app that contains a class that uses a (3rd party) c library via JNI.
This works fine until the web app is redeployed, when I get an exception stating
that the library has already been loaded be another class loader.
From my research I understand that to get round this, I need to include the class
that loads the c lib in the System CLASSPATH, as opposed to the java.class.path.
OK, I can add an entry to the CLASSPATH, but since the class itself is deep in
the web app's .war file, how do I exclude it from the java.class.path?
Alternatively, is there a way to UN-load the library - ideally automatically,
during a redeployment?
TIA
Paul

I've had the same error, and the only thing BEA could say to do was remove the
library from your WAR, and put it somewhere else that is on the system CLASSPATH.
This will prevent the duplication of JNI loading.
It's a hack, but if you have to do it, you have to.
"Paul" <[email protected]> wrote:
>
Hi,
I have a web app that contains a class that uses a (3rd party) c library
via JNI.
This works fine until the web app is redeployed, when I get an exception
stating
that the library has already been loaded be another class loader.
From my research I understand that to get round this, I need to include
the class
that loads the c lib in the System CLASSPATH, as opposed to the java.class.path.
OK, I can add an entry to the CLASSPATH, but since the class itself is
deep in
the web app's .war file, how do I exclude it from the java.class.path?
Alternatively, is there a way to UN-load the library - ideally automatically,
during a redeployment?
TIA
Paul

Similar Messages

  • ClassNotFoundException using JNI and JRE 6.0

    I'm currently experiencing a problem with an application invoked by JNI that works under JRE 1.4 and 5.0, but not 6.0.
    I wrote a standalone app that tests the lines of code in question and ran it from the command prompt using JRE 6.0 and it works ok.
    This has lead me to believe that it has something to do with the JNI classloader as the class that it cannot find is on the classpath.
    Any tips on things I might try?
    Note: This app is also using classes from JavaMail and I have a similar thread open in that forum discussing some of the issues, but it seems to come back to the only difference between the working/non-working versions being JNI...
    Thanks.

    I'm currently experiencing a problem with an application invoked by JNI that works under JRE 1.4 and 5.0, but not 6.0.
    I wrote a standalone app that tests the lines of code in question and ran it from the command prompt using JRE 6.0 and it works ok.
    This has lead me to believe that it has something to do with the JNI classloader as the class that it cannot find is on the classpath.
    Any tips on things I might try?
    Note: This app is also using classes from JavaMail and I have a similar thread open in that forum discussing some of the issues, but it seems to come back to the only difference between the working/non-working versions being JNI...
    Thanks.

  • 64-bit JNI C++ to JAVA invocation multiple threads classloader problem

    Hi ALL,
    I have a C++ app that invokes Java classes on 64-bit Solaris 10 with 64-bit JVM.
    Here is the problem:
    The native non-main (not the thread that initializes the JVM) threads would not be able to find any user-define class.
    Here are the symptoms and observations:
    1. JNIEnv::ExceptionDescribe() showed the following StackOverflowError:
    Exception in thread "Thread-0" java.lang.StackOverflowError
            at java.util.Arrays.copyOf(Arrays.java:2734)
            at java.util.Vector.ensureCapacityHelper(Vector.java:226)
            at java.util.Vector.addElement(Vector.java:573)
            at java.lang.ClassLoader.addClass(ClassLoader.java:173)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)2. The "main thread" that instantiates the JVM has no problem finding and loading any class or method
    3. But the other threads (non-main threads) would not be able to find the user-defined classes unless the classes were already loaded by the main thread.
    4. The non-main threads can find the "standard" java classes with no problem
    5. The same app ran fine on 32-bit system.
    6. Except for the JVM reference is global, each thread acquired JNIEnv by either GetEnv() or AttachCurrentThread().
    Any idea why it is a problem with 64-bit?
    I have the sample program to reproduce this issue in this thread: http://forums.sun.com/thread.jspa?messageID=10885363&#10885363. That was the original thread I raised but I have narrowed it down to a more concrete scenario. That's why I am creating this new thread. I hope this does not break any rule on this forum. If it does, I apologize.
    I really appreciate it if anyone can provide any help/suggestion.
    Regards,
    - Triet

    Here is the sample program. Again, this works on 32-bit but not 64-bit.
    #include <string>
    #include "jni.h"
    #include "TestThread.h"
    static JavaVM *g_pjvm = NULL;  /* denotes a Java VM */
    static JNIEnv *g_penv = NULL;  /* pointer to native method interface */
    void initJVM(char** jvmOptions) {
        printf("RJniTest init starts...\n");
        JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
        JavaVMOption* poptions;
        int optionLen = 0;
        while (jvmOptions[optionLen]) {
            optionLen++;
        printf("RJniTest::init len=%d\n", optionLen);
        if (optionLen > 0) {
            printf("RJniWrapper::init jvmOptions\n");
            poptions = new JavaVMOption[optionLen];
            //poptions[0].optionString = "-Djava.class.path=/usr/lib/java";
            int idx = 0;
            while (jvmOptions[idx]) {
                poptions[idx].optionString = jvmOptions[idx];
                idx++;
        printf("RJniTest::init vm_args: version(%x), nOptions(%d)\n",
                JNI_VERSION_1_6, optionLen);
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = optionLen;
        vm_args.options = poptions;
        vm_args.ignoreUnrecognized = JNI_FALSE;
        // load and initialize a Java VM, return a JNI interface
        // pointer in env
        printf("RJniTest::init creates JVM\n");
        JNI_CreateJavaVM(&g_pjvm, (void**)&g_penv, &vm_args);
        printf("RJniTest init ends\n");
    void findClass(const char* classname) {
        static const char* fname = "justFindClasses";
        printf("%s: findClass: %s\n", fname, classname);
        JNIEnv* jenv;
        jint ret = g_pjvm->GetEnv((void**)&jenv, JNI_VERSION_1_6);
        if (ret == JNI_EDETACHED) {
            ret = g_pjvm->AttachCurrentThread((void**)&jenv, NULL);
            if (ret != JNI_OK || jenv == NULL) {
                printf("%s: get env error: ret=%d\n", ret, fname);
            } else {
                printf("%s: got new env\n", fname);
        } else if (ret == JNI_OK) {
            printf("%s: env already there\n");
        jclass classref;
        classref = jenv->FindClass(classname);
        if (classref == NULL) {
            printf("%s: %s class not found!\n", fname, classname);
            if (jenv->ExceptionOccurred()) {
                jenv->ExceptionDescribe();
                jenv->ExceptionClear();
        printf("%s: found class: %s\n", fname, classname);
    class RJniTestThread : public TestThread {
    public:
        void threadmain();
    void RJniTestThread::threadmain() {
        printf("RJniTestThread::threadmain: Starting testing\n");
        findClass("org/apache/commons/logging/Log");
        findClass("java/util/List");
        printf("RJniTestThread::threadmain: done.\n");
    int main(int argc, char** argv) {
        char **jvmOptions = NULL;
        printf("RJniTestDriver starts...\n");
        if (argc > 1) {
            jvmOptions = new char*[argc];
            for (int i = 0; i < argc ; i ++) {
                jvmOptions[i] = argv[i + 1];
            jvmOptions[argc - 1] = NULL;
        } else {
            int size = 8;
            int i = 0;
            jvmOptions = new char*[size];
            jvmOptions[i++] = (char*) "-Djava.class.path=<list of jar files and path here>";
            jvmOptions[i++] = (char*) "-Djava.library.path=/sandbox/mxdev/3rdparty/java/unix/jdk1.6.0_14/jre/lib/sparc";
            jvmOptions[i++] = (char*) "-Djava.compiler=NONE";
            jvmOptions[i++] = (char*) "-verbose:jni";
            jvmOptions[i++] = (char*) "-Xcheck:jni";
            jvmOptions[i++] = NULL;
        printf("init JVM\n");
        initJVM(jvmOptions);
        // UNCOMMENT HERE
        // findClass("org/apache/commons/logging/Log");
        // findClass("java/util/List");
        // UNCOMMENT END
        printf("start test thread\n");
        RJniTestThread testThread;
        ThreadId tid = testThread.launch();
        printf("wait for test thread\n");
        int ret = pthread_join(tid, NULL);
        printf("RJniTestDriver ends\n");
    }

  • C++ ClassLoader implementation via JNI??

    Ok, I've gotten so far that I can read a .jar file into memory (as a .zip file), I've implemented my own FindClass that extracts the .class from .zip (in memory) and passes the code bytes to JNI's DefineClass . So far so good. That works. BUT: If I in a class (in the jar) want to access another class in the same jar, it will not work as the system default class loader is invoked and the class is of course not found (as the jar is only in memory and not on the HD). I've noticed that DefineClass can be passed a class loader reference (jobject), but how do I make a C++ class loader to be passed as such an object??
    TIA
    /Rob

    Hi,
    why exactly are you implementing a classloader in C++ ?
    Is this some prototype for securely loading classes which can't be decompiled because it's in native code ?
    Here's my theory anyways... could be wrong but worth a shot...
    I think you're probably trying to do too much on the C++ side.
    At best I think the C++ should load the class definition and return an array of bytes representing the class file.
    You call this within your Java implementation of FindClass(), and call defineClass() on the Java side.... eg.
    public MyCPPClassLoader extends ClassLoader
          static
                  // load your native C++ library ( .dll or .so )
                  System.loadLibrary ( "cppLoader" );
         private native byte[] cppLoadClass ( String name );
         protected  Class findClass(String name) 
              // call native library to load the class from an arbitrary source
              byte[] classDef = cppLoadClass ( name );
              // let the normal class loader functionality do the work for us
              return ( defineClass ( name, classDef, 0, classDef.length ) );
    }regards,
    Owen

  • Using JNI in applets: impossible due to classloader limitations?

    Hello,
    I attempted to post this question on java.net but no one seemed to know the answer. I am especially hoping that the Engineers who work on the Java Plugin will comment on this question. Thank you.
    http://forums.java.net/jive/thread.jspa?messageID=248215
    Gili

    Just a workaround: drag the Properties panel to the bottom dock (where the Timeline is). This suppose you are in Expert mode which you can achieve by enabling the fourth option in Preferences, General: Enable drag...

  • Calling a third-party library from JNI-enabled C++ code

    Hi everyone,
    I have some existing C++ application code that extracts data from a file in a special format (HDF5). This code uses a static library (third party) to decode the file format. I would like to wrap this application code in a JNI wrapper so that I can call the code from Java. So I have a situation like this:
    Java front end -> application code (C++) -> static library (C++)
    I have compiled JNI headers and modified the application code accordingly. I created a shared library by bundling the application code together with the static library (using gcc 3.2.2 on Red Hat Linux 9):
    g++ -shared hdf5_jni.cc -o libhdf5_jni.so -I<include path> -L<static library path> -lhdf5
    (the <static library path> contains the static library libhdf5.a). This creates a shared library which contains the application code and the relevant bits of the static library.
    When I call the Java front end, the shared library (libhdf5_jni.so) is correctly found and accessed. However, I get an UnsatisfiedLinkError which I don't understand:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: <blah>/lib/libhdf5_jni.so: <blah>/lib/libhdf5_jni.so: undefined symbol: _Z4formPKcz
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1485)
    ... etc
    I have no idea what the undefined symbol "_Z4formPKcz" represents. It's not part of the application code or the static library.
    Here's some more info that might help diagnosis:
    1) The problem seems to be due to the approach of having a three-step process (Java code calling bespoke shared library which includes unmodified 3rd-party code). I get an identical error (including the mysterious "_Z4formPKcz" symbol) when trying to do something similar with a different 3rd-party static library.
    2) When I simply have Java code calling C++ code which I have written myself (no calls to static library methods), I have no problems, i.e. there doesn't seem to be a problem with the way I set up the JNI wrappers or the application code, or in the way I create the shared library.
    3) When I simply have C++ code calling the static libraries (i.e. no Java wrapper) I have no problems, i.e. there doesn't seem to be a problem with the application code or the static libraries.
    4) The static libraries were compiled from source using the same compiler that I used to compile the application code.
    5) I'm using J2SDK 1.4.2 on Red Hat Linux 9, although I've tried other versions of the SDK and had the same problem.
    I've done a lot of web searches on the "_Z4formPKcz" symbol and have turned up absolutely nothing (zero Google hits!).
    Any help would be very much appreciated.
    Thanks, Jon

    Thanks chrisswhite,
    I should have mentioned that I tried this too and it didn't solve the problem. You're right though, I should be compiling with -fPIC anyway.
    Jon

  • Error in Java Runtime Environment when running JNI native library

    Hi,
    I am kinda new to JNI but understand it [and done some tutorials]. I am trying to implement JavaStyle [ a Java vst host that uses JNI ] and have reached a point where i successfully build the native code to a dll, and almost manage to load the native dll library. I do not get a Unsatisfied Link Error, but instead have the JVM close due an internal error.
    I am completely lost and dont know what to try now, and I would appreciate any help offered.
    I have debugged and the error arrives at the System.load line of code:
      static {
        System.out.print("Pre loadLibrary..."); 
        System.loadLibrary("JaVaSTyle");
        System.out.println("JavaStyle dll loaded in JVSTLibrary");
      }Detail: I compiled the native library with MS visual studio .NET 2003 using the project settings supplied from the CVS repository.
    I use Netbeans 6.0 for the java side of things. The console output is:
    # An unexpected error has been detected by Java Runtime Environment:
    #  Internal Error (0xe0434f4d), pid=1500, tid=6012
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # C  [kernel32.dll+0x12a5b]
    # An error report file with more information is saved as hs_err_pid1500.logand the error report is :
    # An unexpected error has been detected by Java Runtime Environment:
    #  Internal Error (0xe0434f4d), pid=1500, tid=6012
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # C  [kernel32.dll+0x12a5b]
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    ---------------  T H R E A D  ---------------
    Current thread (0x00297000):  JavaThread "main" [_thread_in_native, id=6012]
    siginfo: ExceptionCode=0xe0434f4d
    Registers:
    EAX=0x0090f4c0, EBX=0x00000001, ECX=0x000b0fd0, EDX=0x00000000
    ESP=0x0090f4bc, EBP=0x0090f510, ESI=0x00000000, EDI=0x00000000
    EIP=0x7c812a5b, EFLAGS=0x00000246
    Top of Stack: (sp=0x0090f4bc)
    0x0090f4bc:   000b0fd0 e0434f4d 00000001 00000000
    0x0090f4cc:   7c812a5b 00000000 791b9d02 02ea1198
    0x0090f4dc:   07624998 000b0fd0 0090f4fc 791be271
    0x0090f4ec:   000ae008 00000002 07624998 00000000
    0x0090f4fc:   0090f50c 791be286 000ae008 07624998
    0x0090f50c:   0090f51c 0090f568 7921020d e0434f4d
    0x0090f51c:   00000001 00000000 00000000 000b0fd0
    0x0090f52c:   0090f578 00000001 7c812a5b 0090f1f0
    Instructions: (pc=0x7c812a5b)
    0x7c812a4b:   8d 7d c4 f3 a5 5f 8d 45 b0 50 ff 15 08 15 80 7c
    0x7c812a5b:   5e c9 c2 10 00 85 ff 0f 8e 36 93 ff ff 8b 55 fc
    Stack: [0x008c0000,0x00910000),  sp=0x0090f4bc,  free space=317k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C  [kernel32.dll+0x12a5b]
    C  [mscorwks.dll+0x6020d]
    C  [mscorwks.dll+0x60190]
    C  [mscorwks.dll+0x60144]
    C  [mscorwks.dll+0xa6dcb]
    C  [mscorwks.dll+0x26a7e]
    C  0x000b15f6
    j  java.lang.ClassLoader$NativeLibrary.load(Ljava/lang/String;)V+0
    j  java.lang.ClassLoader.loadLibrary0(Ljava/lang/Class;Ljava/io/File;)Z+300
    j  java.lang.ClassLoader.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)V+268
    j  java.lang.Runtime.loadLibrary0(Ljava/lang/Class;Ljava/lang/String;)V+54
    j  java.lang.System.loadLibrary(Ljava/lang/String;)V+7
    j  org.tango.JaVaSTyle.JVSTLibrary.<clinit>()V+10
    v  ~StubRoutines::call_stub
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j  java.lang.ClassLoader$NativeLibrary.load(Ljava/lang/String;)V+0
    j  java.lang.ClassLoader.loadLibrary0(Ljava/lang/Class;Ljava/io/File;)Z+300
    j  java.lang.ClassLoader.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)V+268
    j  java.lang.Runtime.loadLibrary0(Ljava/lang/Class;Ljava/lang/String;)V+54
    j  java.lang.System.loadLibrary(Ljava/lang/String;)V+7
    j  org.tango.JaVaSTyle.JVSTLibrary.<clinit>()V+10
    v  ~StubRoutines::call_stub
    j  org.tango.JaVaSTyle.Main.main([Ljava/lang/String;)V+3
    v  ~StubRoutines::call_stub
    ---------------  P R O C E S S  ---------------
    Java Threads: ( => current thread )
      0x02a6d800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=4752]
      0x02a68c00 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4472]
      0x02a67800 JavaThread "Attach Listener" daemon [_thread_blocked, id=2016]
      0x02a66c00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=4328]
      0x02a62400 JavaThread "Finalizer" daemon [_thread_blocked, id=5072]
      0x02a5dc00 JavaThread "Reference Handler" daemon [_thread_blocked, id=5552]
    =>0x00297000 JavaThread "main" [_thread_in_native, id=6012]
    Other Threads:
      0x02a5cc00 VMThread [id=4660]
      0x02a6f000 WatcherThread [id=3864]
    VM state:not at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: None
    Heap
    def new generation   total 960K, used 199K [0x22970000, 0x22a70000, 0x22e50000)
      eden space 896K,  22% used [0x22970000, 0x229a1ff0, 0x22a50000)
      from space 64K,   0% used [0x22a50000, 0x22a50000, 0x22a60000)
      to   space 64K,   0% used [0x22a60000, 0x22a60000, 0x22a70000)
    tenured generation   total 4096K, used 0K [0x22e50000, 0x23250000, 0x26970000)
       the space 4096K,   0% used [0x22e50000, 0x22e50000, 0x22e50200, 0x23250000)
    compacting perm gen  total 12288K, used 23K [0x26970000, 0x27570000, 0x2a970000)
       the space 12288K,   0% used [0x26970000, 0x26975c48, 0x26975e00, 0x27570000)
        ro space 8192K,  66% used [0x2a970000, 0x2aebf860, 0x2aebfa00, 0x2b170000)
        rw space 12288K,  52% used [0x2b170000, 0x2b7bf078, 0x2b7bf200, 0x2bd70000)
    Dynamic libraries:
    0x00400000 - 0x00423000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\java.exe
    0x7c900000 - 0x7c9b0000      C:\WINDOWS\system32\ntdll.dll
    0x7c800000 - 0x7c8f5000      C:\WINDOWS\system32\kernel32.dll
    0x77dd0000 - 0x77e6b000      C:\WINDOWS\system32\ADVAPI32.dll
    0x77e70000 - 0x77f02000      C:\WINDOWS\system32\RPCRT4.dll
    0x77fe0000 - 0x77ff1000      C:\WINDOWS\system32\Secur32.dll
    0x7c340000 - 0x7c396000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\msvcr71.dll
    0x6d870000 - 0x6daba000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\client\jvm.dll
    0x7e410000 - 0x7e4a0000      C:\WINDOWS\system32\USER32.dll
    0x77f10000 - 0x77f57000      C:\WINDOWS\system32\GDI32.dll
    0x76b40000 - 0x76b6d000      C:\WINDOWS\system32\WINMM.dll
    0x76390000 - 0x763ad000      C:\WINDOWS\system32\IMM32.DLL
    0x5cd70000 - 0x5cd77000      C:\WINDOWS\system32\serwvdrv.dll
    0x5b0a0000 - 0x5b0a7000      C:\WINDOWS\system32\umdmxfrm.dll
    0x003a0000 - 0x003ad000      C:\WINDOWS\system32\myokent.dll
    0x6d3c0000 - 0x6d3c8000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\hpi.dll
    0x76bf0000 - 0x76bfb000      C:\WINDOWS\system32\PSAPI.DLL
    0x6d820000 - 0x6d82c000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\verify.dll
    0x6d460000 - 0x6d47f000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\java.dll
    0x6d860000 - 0x6d86f000      C:\Program Files\Java\jdk1.6.0_03\jre\bin\zip.dll
    0x10000000 - 0x10018000      D:\NetbeansWorkspace\myJavaStyle\JaVaSTyle.dll
    0x79170000 - 0x79196000      C:\WINDOWS\system32\mscoree.dll
    0x10480000 - 0x1053c000      C:\WINDOWS\system32\MSVCP71D.dll
    0x10200000 - 0x10287000      C:\WINDOWS\system32\MSVCR71D.dll
    0x77f60000 - 0x77fd6000      C:\WINDOWS\system32\SHLWAPI.dll
    0x77c10000 - 0x77c68000      C:\WINDOWS\system32\msvcrt.dll
    0x791b0000 - 0x79412000      C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorwks.dll
    0x79040000 - 0x79085000      C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
    0x7c9c0000 - 0x7d1d6000      C:\WINDOWS\system32\SHELL32.dll
    0x773d0000 - 0x774d3000      C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll
    0x5d090000 - 0x5d12a000      C:\WINDOWS\system32\comctl32.dll
    0x79780000 - 0x79980000      c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll
    0x774e0000 - 0x7761d000      C:\WINDOWS\system32\ole32.dll
    0x79430000 - 0x7947c000      C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\MSCORJIT.DLL
    0x51a70000 - 0x51af0000      C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\diasymreader.dll
    VM Arguments:
    java_command: org.tango.JaVaSTyle.Main
    Launcher Type: SUN_STANDARD
    Environment Variables:
    CLASSPATH=.;C:\jdk1.5.0_09\bin;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip
    PATH=C:\Program Files\MiKTeX 2.7\miktex\bin;c:\program files\imagemagick-6.3.7-q16;C:\texmf\miktex\bin;C:\Program Files\ActiveState Komodo IDE 4.2\;C:\Program Files\Autodesk\Maya2008\bin;C:\Python25\;C:\Program Files\PC Connectivity Solution\;C:\ORANT\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\GPS Pathfinder Office 3.00;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\ENGLISH;C:\Program Files\Common Files\Motorola\Toolbox;C:\PROGRA~1\COMMON~1\Motorola\Toolbox;C:\Program Files\Novell\ZENworks\;C:\Program Files\Novell\SecureLogin;C:\Program Files\Smart Projects\IsoBuster;C:\Latex\MikTeX\V2.10;C:\PROGRA~1\CA\Common\SCANEN~1;C:\Program Files\CA\Common\ScanEngine;C:\Program Files\CA\SharedComponents\CAUpdate\;C:\Program Files\CA\SharedComponents\ThirdParty\;C:\Program Files\CA\SharedComponents\SubscriptionLicense\;C:\PROGRA~1\CA\ETRUST~1;C:\Program Files\QuickTime\QTSystem\;C:\cygwin\bin;C:\Program Files\Tcl\bin;D:\netbeansWorkspace\myJavaStyle;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;C:\Program Files\Csound\bin;C:\Program Files\CVSNT\
    USERNAME=hectorj
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 13 Stepping 8, GenuineIntel
    ---------------  S Y S T E M  ---------------
    OS: Windows XP Build 2600 Service Pack 2
    CPU:total 1 (1 cores per cpu, 1 threads per core) family 6 model 13 stepping 8, cmov, cx8, fxsr, mmx, sse, sse2
    Memory: 4k page, physical 1047920k(270244k free), swap 2520456k(1654520k free)
    vm_info: Java HotSpot(TM) Client VM (1.6.0_03-b05) for windows-x86, built on Sep 24 2007 22:24:33 by "java_re" with unknown MS VC++:1310

    Something is wrong with the library.
    Staring at java code will not help you figure that out.
    Maybe it isn't intended to be loaded in java but instead it loads java itself?
    If not then write a C/C++ basic app that links that dll in and see if you can at least get it to start.

  • Error in SAPGUI-on AIX- Can't load JNI library

    Error in SAPGUI-on AIX- Can't load JNI library
    I am getting error as below:
    ^C# ./sapgui /H/punlparidm06 /S/sapdbIND
    ERROR #############################
    07.03. 12:48:37.619 ERROR: Attempt to load shared library /local/SAPClients/SAPGUI7.00rev2.1/bin/libJPlatin.so failed.
    07.03. 12:48:37.619 ERROR: The library file exists, so either the program
    07.03. 12:48:37.619 ERROR: don't has the privileges to access the library
    07.03. 12:48:37.619 ERROR: or the library is not loadable by the shared object loader
    07.03. 12:48:37.619 ERROR: Technical information:
    07.03. 12:48:37.619 ERROR: Error location: GuiJniLoader.loadPlatinLibrary()
    07.03. 12:48:37.619 ERROR: Error message : /local/SAPClients/SAPGUI7.00rev2.1/bin/libJPlatin.so: load ENOEXEC on shared library(s) /local/SAPClients/SAPGUI7.00rev2.1/bin/libJPlatin.so
    ERROR #############################
    java.lang.UnsatisfiedLinkError: /local/SAPClients/SAPGUI7.00rev2.1/bin/libJPlatin.so: load ENOEXEC on shared library(s) /local/SAPClients/SAPGUI7.00rev2.1/bin/libJPlatin.so
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2144)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1973)
    at java.lang.Runtime.load0(Runtime.java:773)
    at java.lang.System.load(System.java:887)
    at com.sap.platin.r3.util.GuiJniLoader.loadPlatinLibrary(GuiJniLoader.java:114)
    at com.sap.platin.r3.protocol.diag.JniAgiLibAdaptor.<init>(JniAgiLibAdaptor.java:24)
    at com.sap.platin.r3.protocol.diag.GuiDiagToAutomationParser.configure(GuiDiagToAutomationParser.java:289)
    at com.sap.platin.base.connection.GuiConnection.open(GuiConnection.java:316)
    at com.sap.platin.base.application.GuiApplication.createConnection(GuiApplication.java:860)
    at com.sap.platin.base.logon.GuiImpl.evalCommandLine(GuiImpl.java:275)
    at com.sap.platin.base.logon.GuiImpl.<init>(GuiImpl.java:44)
    at com.sap.platin.base.logon.GuiImpl.main(GuiImpl.java:447)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
    at java.lang.reflect.Method.invoke(Method.java:391)
    at com.sap.platin.micro.Microkernel.invokeMainMethod(Microkernel.java:1670)
    at com.sap.platin.micro.Microkernel.startApplication(Microkernel.java:1750)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
    at java.lang.reflect.Method.invoke(Method.java:391)
    at com.sap.platin.Gui.main(Gui.java:65)
    java.lang.Exception: JniAgiLibAdaptor.<init>: Cannot load JNI library
    at com.sap.platin.r3.protocol.diag.JniAgiLibAdaptor.<init>(JniAgiLibAdaptor.java:25)
    at com.sap.platin.r3.protocol.diag.GuiDiagToAutomationParser.configure(GuiDiagToAutomationParser.java:289)
    at com.sap.platin.base.connection.GuiConnection.open(GuiConnection.java:316)
    at com.sap.platin.base.application.GuiApplication.createConnection(GuiApplication.java:860)
    at com.sap.platin.base.logon.GuiImpl.evalCommandLine(GuiImpl.java:275)
    at com.sap.platin.base.logon.GuiImpl.<init>(GuiImpl.java:44)
    at com.sap.platin.base.logon.GuiImpl.main(GuiImpl.java:447)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
    at java.lang.reflect.Method.invoke(Method.java:391)
    at com.sap.platin.micro.Microkernel.invokeMainMethod(Microkernel.java:1670)
    at com.sap.platin.micro.Microkernel.startApplication(Microkernel.java:1750)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
    at java.lang.reflect.Method.invoke(Method.java:391)
    at com.sap.platin.Gui.main(Gui.java:65)
    ERROR #############################
    07.03. 12:51:52.173 ERROR: GuiConnection: Connect failed
    07.03. 12:51:52.173 ERROR: JniAgiLibAdaptor.<init>: Cannot load JNI library
    ERROR #############################

    Hi,
    It seems to be a permission issue.
    Just check the permissions and grant 755 using chmod comand.
    Hope it helps.
    Reward suitable points!!!!!

  • Problem :  Native Library already loaded in another classloader

    I created a shared library HaspKeyAPI.dll by using JNI and add path to Java class library. I need to call native functions in my servletAction class to check some information in a key. Sometimes not always, I met �java.lang.UnsatisfiedLinkError: Native Library C:\eclipse\workspace\HaspKey\SharedLib\HaspKeyAPI.dll already loaded in another classloader� problem. I have to restart tomcat server then to restart my web app.
    Does anyone know how to fix it?
    Thank you in advance!
    ////////////////////////////////////my native function class, a singleton class////////////////////////////////
    package haspkey.api;
    import java.util.Collection;
    import java.util.Vector;
    import haspkey.HardwareSecurityKey;
    Public class HaspKeyAPI {
    Public static final int KEYEXIST = 1;
    //A Singleton Class
    private static HaspKeyAPI haspKeyAPI;
    private HaspKeyAPI()
    public static HaspKeyAPI getSingletonObject()
    if ( haspKeyAPI== null)
    haspKeyAPI = new HaspKeyAPI();          
    return haspKeyAPI;
    public Object clone()
         throws CloneNotSupportedException
    throw new CloneNotSupportedException();
    /**********use native functions to call hasp C API***********/
    public native int keyPresent(int password1, int password2);
    public native int getId(int password1, int password2);
    public native void readBlock(int startMemoryLocation, int size,
    byte[] block, int password1, int password2);
    public native void writeBlock(int startMemoryLocation,int size, byte[] block, int password1,
    int password2);
    public native boolean decodeData(int size, byte[] block, int password1,
    int password2);
    public native boolean encodeData(int size, byte[] block, int password1,
    int password2);
    static {
    System.loadLibrary("HaspKeyAPI");
    private int getPrivMachineSpeed(boolean decrypt, int pass1, int pass2, String MLOCRTypeCode){
    byte[] block = new byte[8];
    int privMachineSpeed = 0;
    boolean isNumeric = true;;
    readKeyMemory(40,8,block, decrypt, pass1, pass2);
    if(block.length!=8){
    return -1;
    }else{
    String s = new String(block);
    for(int n=0; n<3; n++){
    if(s.charAt(n)<48 || s.charAt(n)>57){
    isNumeric = false;
    if(isNumeric){
    privMachineSpeed = Integer.parseInt(s.substring(0,3));
    return privMachineSpeed;
    public HardwareSecurityKey getHardwareSecurityKey(boolean decrypt, int pass1, int pass2, String AuthorizationCodes,String MLOCRTypeCode){
    HardwareSecurityKey key = new HardwareSecurityKey();
    if(keyPresent(pass1,pass2)==KEYEXIST){
    key.setPrivKeyID(getId(pass1, pass2));
    key.setPrivMachineSpeed(getPrivMachineSpeed(true, pass1,pass2, MLOCRTypeCode));
    }else{
    return null;
    /////////////////////////////// a class include some static final information to call the native function///////////////
    import com.bowebellhowell.haspkey.api.HaspKeyAPI;
    import com.bowebellhowell.winsort.vo.haspkey.HardwareSecurityKey;
    public class HaspKey{
    public static final String MLOCRTypeCode ="mmmmmmmmmmmmmmm";
    public static final String AuthorizationCodes = "bbbbbbbbbbbbbbbb";
    public static final int p1 = 0;
    public static final int p2 = 0;
    public static HardwareSecurityKey getHardwareSecurityKey(){
    HaspKeyAPI key = HaspKeyAPI.getSingletonObject();
    return key.getHardwareSecurityKey(true,p1,p2,AuthorizationCodes,MLOCRTypeCode);
    /////////////////////////////////// a servlet to call native function///////////////////////////////////
    public class LogonAction extends Action {
         public ActionForward execute(
              ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response)
              throws Exception {
              int n = HaspKey.isKeyPresent();
              if(n!=1){
              if(n==2){
              message = "KeyDriverNotMatch";          
              }else if(n==3){
              message = "KeyOldModel";
              }else if(n==4){
              message = "KeyPasswordNotMatch";
              }else if(n==-1){
              message = "keyNotExist";
              request.getSession().setAttribute("message",message);
    java.lang.UnsatisfiedLinkError: Native Library C:\eclipse\workspace\HaspKey\SharedLib\HaspKeyAPI.dll already loaded in another classloader
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1551)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at haspkey.api.HaspKeyAPI.<clinit>(HaspKeyAPI.java:76)
    at util.HaspKey.isKeyPresent(HaspKey.java:35)
    at LogonAction (LogonAction .java:65)

    Hi EveryBody:
    i working in 2 servlets, these servlets import a login.jar library and login.jar call to Login.dll (a native Library)
    then. when i start second servlet i have this message
    java.lang.UnsatisfiedLinkError: Native Library dllLogin.dll already loaded in another classloader
    i read about class loader and i know about a only one load for native library but i don't know how resolve this exception because both servlets need dllLogin.dll to validate the user
    please anybody knows how or have any idea?
    Kind Regards
    Edson
    --sorry i know. my english is very bad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem executing jni code

    I'm working with jni for java and c in fedora core. I could compile sucessfully but at the last step while executiton it is giving the follwing error
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no HelloNative in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at HelloNative.<clinit>(HelloNative.java:6)
    at HelloNativeTest.main(HelloNativeTest.java:5)
    I also setted my path variable
    LD_LIBRARY_PATH=`pwd`
    export LD_LIBRARY_PATH
    but still not working how to solve the problem. Please help me in this aspect.
    Waiting for your responce.

    HI,
    Thank you. These are all the files present in the current directory. But still is is not working. I couldnt understand the cause.
    HelloNative.cc HelloNative.java HelloNativeTest.java
    HelloNative.class HelloNative.so
    HelloNative.h HelloNativeTest.class
    This is the code for HelloNative.cc which compiled well and given the output file HelloNative.cc
    # include "HelloNative.h"
    # include <stdio.h>
    #include <jni.h>
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/shm.h>
    #include <sys/mman.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    JNIEXPORT void JNICALL Java_HelloNative_greeting
    (JNIEnv * env, jclass c1)
    printf("Hello world!");
    this is the code for HelloNative.java
    public class HelloNative
    public native static void greeting();
    static
    System.loadLibrary("HelloNative");
    Then what is the problem i couldnt understand

  • Using JNI with weblogic JSP & Servlets

    I want to use native libraries from JSP and Servlets.
              Everything works fine befire redeploying.
              After redeploying there is an error:
              Servlet failed with Exception
              java.lang.UnsatisfiedLinkError: Native Library D:\WINNT\system32\XXXX.dll
              already loaded in another classloader
              at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1346)
              at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
              at java.lang.Runtime.loadLibrary0(Runtime.java:749)
              at java.lang.System.loadLibrary(System.java:820)
              at HelloWorld.<clinit>(HelloWorld.java:9)
              at NativeTestServlet.doGet(NativeTestServlet.java:31)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :208)
              at
              weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
              ntext.java:1127)
              at
              weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
              :1529)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              Can anybody solve it?
              Best wishes, Oleg.
              

    Java will not allow us to reload any class that is dependent on a native
              library. I suggest that any classes that depend on native code should be
              put in the system classpath. If you change these classes or the native
              library you will need to restart your server.
              Sam
              "Jennifer Yin" <[email protected]> wrote in message
              news:[email protected]...
              > Oleg-
              >
              > I'm having the exact same problem and was wondering how you fixed it. I
              ran
              > javah -jni <classname> to verify the correct method call and have also
              verified
              > that the library file is included in the system path.
              >
              > Any other suggestions?
              >
              > Jennifer
              >
              > Oleg wrote:
              >
              > > I want to use native libraries from JSP and Servlets.
              > > Everything works fine befire redeploying.
              > > After redeploying there is an error:
              > >
              > > Servlet failed with Exception
              > > java.lang.UnsatisfiedLinkError: Native Library
              D:\WINNT\system32\XXXX.dll
              > > already loaded in another classloader
              > > at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1346)
              > > at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
              > > at java.lang.Runtime.loadLibrary0(Runtime.java:749)
              > > at java.lang.System.loadLibrary(System.java:820)
              > > at HelloWorld.<clinit>(HelloWorld.java:9)
              > > at NativeTestServlet.doGet(NativeTestServlet.java:31)
              > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              > > at
              > >
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              > > :208)
              > > at
              > >
              weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
              > > ntext.java:1127)
              > > at
              > >
              weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
              > > :1529)
              > > at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              > > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              > > >
              > >
              > > Can anybody solve it?
              > >
              > > Best wishes, Oleg.
              >
              

  • Servlets And JNI.. real urgent help.

    Hi all,
    I have the JNI code integrated to the servlet .The servlet works fine at first time.but when i modified some source code of servlet (not native library) and redeploy it,then reload the same servlet in web browser ,i get "Native library already loaded in another classloader java.lang.UnsatisfiedLinkError" error.
    Any solution to this ???
    Thanks
    jetdvk

    Have you fixed this?
    I presume you are hot deploying the servlet ? if so then i also presume that you have either some static code or some run once code that loads your native code when your class is used for the first time.
    This code is being ran again as the class is being reloaded, therefore you have two choices,
    1) wrap the call loading the native library, and just ignore the exception. Then call a check method in the native code to make sure that the library was loaded.
    2) Move the code that loads the native library out to another class that is not hot deployed. Your servlet can call this when it is first accessed, and the other class will know whether it has already loaded the dll and will not attempt to load it again.

  • JNI bug?

    Hi,
    I hope this is an OK place to report bugs. The opening message on the forum
    points to the website for bug reporting, but that's only about support and
    I'm not looking for support, I just want to report a bug (I think).
    Anyway. I'm playing with JRocket 7 over Win2K sp3. The version string is:
    $ ./java -version
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0)
    BEA Weblogic JRockit(R) Virtual Machine (build
    7.0-1.4.0-win32-GARAK-20020830-1714, Native Threads, Generational Concurrent
    Garbage Collector)
    I'm using JNI and though most things seem to work OK with JRocket, I've
    found that using JNI to call java.lang.Class.getDeclaredMethods() on any
    class object will trigger a Null pointer exception. The attached program
    demonstrates this. If you compile it up, and then call it with the full
    path to the JVM.DLL then it tries to print the results of listing all the
    methods of java.lang.Class. With Sun's J2SDK 1.4.1 (and before), and IBM's
    1.2-style JDK, it works fine. Using JRocket it throws a
    NullPointerException. I'm using all default options for JRocket.
    I'm using the CallObjectMethodA() function with a NULL argument array to
    invoke the method ('cos that's what my real code does), but providing a real
    non-NULL array, or using the varags form, CallObjectMethod(), makes no
    difference.
    BTW, I'm finding a few other places where JR's JNI is inconsistent with
    Sun's (not necessarily bugs, though I think some are). Should I post them
    here ? Or email someone ? Or just keep 'em to myself ;-)
    -- chris
    [JNITest.zip]

    Staffan,
    I had a look at this and can confirm
    that this is indeed a problem in JRockit. Unfortunately there is no easy
    workaround other than calling Class.getDeclaredMethods() from a Javamethod
    instead of directly from JNI. Can you explain a bit more about your
    application and what you want to achieve?Thank for confirming the bug (which, incidentally also affects the other
    get[Declared]{Field/Method/Constructor/Class}[s] methods -- with the
    exception of getInterfaces(), for some reason).
    What I'm doing is using JNI to drive the JVM from Smalltalk. I'm using
    reflection to generate (on-the-fly) wrapper (Smalltalk) classes
    corresponding to Java classes and whose instances internally use JNI to
    invoke the Java methods, etc. So it's rather important that reflection
    actually works ;-)
    There's no great difficulty in setting up a forwarding Java class that
    invokes the reflection methods of java.lang.Class, and the forwarding
    class's methods can be invoked from JNI without problems, so I've been able
    to put together a patch that allows my stuff to work over JRockit.
    You asked about the other inconsistencies I've found. There are only 3 (now
    I've had a chance to analyse what I was seeing a bit better -- not to
    mention getting rid of a couple of bugs of my own...). None is especially
    important, and they are kind of esoteric too, but FWIW:
    The JNI DefineClass() method: Sun's implementation will accept NULL values
    for either or both of the name and the class loader. JRockit seems to get
    an access violation (this is on Windows) if given a NULL name, and
    apparently calls exit() if it is given a NULL class loader. I think that
    the Sun behaviour is better since both the name and the classloader are
    optional using the Java interfaces.
    Given a couple of Java classes:
    class Base
    Base(int i) {}
    Base(boolean b) {}
    class Derived
    extends Base
    Derived(int i) {}
    Attempting to use one of Base's constructors as if they were "inherited" by
    Derived acts differently on Sun and JRockit. Code like (I'm typing this off
    the top of my head):
    jclass derived = jnvEnv->findClass("Derived");
    jmethod mid = jniEnv->GetMethodID(derived, "<init>", "(Z)V");
    jvalue args[1];
    args[1].z = true;
    jobject new = jniEnv->CallConstructorA(derived, mid, args);
    will fail on Sun's VM since the call to GetMethodID() will fail with a
    NoSuchMethodError (correctly, I think) whereas JRockit will return a handle
    on the constructor with the same signature in the superclass. When that
    "inherited" constructor is then used the created object is of class Base,
    even though the constructor was invoked on Derived.
    Given the following:
    class Base { public static int ambiguous = 100; }
    interface Interface { int ambiguous = -100; }
    class Derived extends Base implements Interface { }
    Any reference to Derived.ambiguous from Java will trigger a compile-time
    error. However it is legal to do the equivalent from JVM bytecodes (a
    getstatic with class="Derived" name="ambiguous" type="I") and is defined (as
    I read the spec) to be -100. I.e. the JVM resolves the field reference to
    the interface. Under both the Sun and JRockit JVMs that works as expected.
    Doing the equivalent from JNI:
    jclass derived = jniEnv->findClass("Derived");
    jfield fid = jniEnv->GetFieldID(derived, "ambiguous", "I");
    jint value = jniEnv->GetStaticIntField(derived, fid);
    returns -100 on Sun's JVM (which is what I'd expect), but returns 100 on
    JRockit (which I think is wrong).
    Like I said, esoteric...
    Hope this helps.
    -- chris

  • About JNI

    Hi,
    I am new to JNI programming. I tested the following hello world programm:
    HelloWorld.java:
    class HelloWorld {
    public native void displayHelloWorld();
    static {
    System.loadLibrary("HelloWorld");
    public static void main(String[] args) {
    new HelloWorld().displayHelloWorld();
    HelloWorld.cpp:
    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    printf("Hello world!\n");
    return;
    I compiled the C++ code with Visual C++ 6.0, I created de project with the opcion "MFC AppWizard (dll)"
    and when I compiled the code with C++ I have an error "fatal error C1083: cannot open include file: �jni.h�: no such file or directory
    error executing cl.exe"
    I mean the c++ code was not compiled and when I did java HelloWord I had the follow error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: displayHelloWord
         at HelloWorld().displayHelloWorld(Native Method)
         at HelloWorld().main(HelloWorld.java)
    I have no idea what this mean
    Anyone have an idea? please help me
    Thank you in advance.

    Hi
    I could compile the file C++ and I tried to run the file HolaMundo.java but I have the follow error
    C:\Documents and Settings\yamilet\Mis documentos\prueba\intento>java -Djava.libr
    ary.path=. HolaMundo
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no HolaMundo in java.
    library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at HolaMundo.<clinit>(HolaMundo.java:9)
    C:\Documents and Settings\yamilet\Mis documentos\prueba\intento>
    I have the files HolaMundo.h and HolaMundo.java inside the directory Hola.
    The directory Hola had the C++'project and the file HolaMundo.dll was inside the Debuc'folder
    and Debuc'folder was automatic generate for the C++'compiler.
    I mean The loadLibrary isn't work, I mean the java'compiler don't know where is the file HolaMundo
    I tried to put it inside the directory Debug but I still the error.
    I tried to put it inside the directory hola but I still the error.
    The file HolaMundo.java is
    public class HolaMundo
         private native void saluda();
         public static void main(String[] args)
         new HolaMundo().saluda();
         static
         System.loadLibrary("HolaMundo");
    HolaMundo is the file .dll and it is inside the directory Debug
    Have you any idea? Please help me
    Thank for advance.

  • JNI Calling Java code when attaching to existing JVM

    I've got an Active/X that runs within IE, and also makes JNI calls (via the Invocation API) to Java code. Running within IE means there's already a JVM around, so I attach to it using JNI_GetCreatedJavaVMs
    This is fine. The problem is that I can't use the JNI findClass() to locate my Java classes, because I have no control over the classpath that the JVM is using to locate classes. The only solution I can think of so far is to either add my classes as part of the JVM, OR find out the classpath of the existing JVM (using System.getProperty("java.class.path") and copy my classes into that directory.
    Both solutions look ugly - anyone know of a cleaner way ?
    Mark.

    Toby, thanks for the reply.
    You're welcome.
    I notice from elsewhere on this forum, you're clearly a JNI expert.
    I've been known to work with it a little from time to time. =)
    My code has to work with JDK 1.1 so URLClassLoader is out. Writing my own classloader is fine, but how do I load it in the first place ? Is there something in JNI I've missed ?
    Possibly. Using DefineClass() you can load a class into the virtual machine, given it's byte-code. Now here's the tricky part. First, write your ClassLoader. It will be easiest if it doesn't rely on any other classes other than what is core to the JRE. Once you compile that classloader, you then need to include the bytecode as a resource in your executable/dll. Then, at runtime, you can load that resource, and use DefineClass to class-load it. Once you've class-loaded it, you can use NewObject, GetMethodID, CallXXXMethod, etc... to do the other class loading you need to do.
    Trust me, this really isn't as hard as it might sound.
    God bless,
    -Toby Reyelts
    As always, I recommend you check out the free, open-source JNI toolkit, Jace, at http://jace.reyelts.com/jace.

Maybe you are looking for