Performance of System.loadLibrary in JNI

I am working on a solution that uses System.loadLibrary to load a dll during the initialisation of an Applet. This is to enable the Applet to use Windows mutex objects. The Applet is downloaded (if not cached) from a remove server as part of an HTML page. The dll is located on the local machine in a directory at the front of the PATH environment variable. The dll is only 40 KB however the System.loadLibrary call takes 4525ms to load the dll. This consitutes 99% of the Applet initialisation time.
Does any one have any suggestions how I can improve the speed of loading / using this dll?
Thanks,
James

The dll is only 40 KB however the System.loadLibrary call takes 4525ms to load the dll. Perhaps this is because:
This is to enable the Applet to use Windows mutex objects.and you're doing something wrong.

Similar Messages

  • JNI System.loadLibrary troubles

    Hello again!
    I am so close to finishing this program I can taste it! But�
    OK, I am doing a bit of JNI. All appears to be well except my program can�t seem to use
    System.loadLibrary("myCPPdll");
    to find the dll file I need to run the C++ code.
    I�ve tired replacement with
    Runtime.getRuntime().loadLibrary("myCPPdll ");
    just for grins with the same result.
    I also tried
    System.loadLibrary("C:/fullPath/myCPPdll");
    with no luck.
    The error message I get, regardless if I run from the command line or via Eclipse is
    java.lang.UnsatisfiedLinkError: no myCPPdll in java.library.path.
    Possibly related: when I use the tutorial form
         Static
    System.loadLibrary("myCPPdll");
    my compiler tells me it can�t find the main. Just how critical is it to have it in this static format? It compiles great without the System call embedded in the static{} block!
    Thanks for your time!

    I added the .dll and get the same error. It was my
    understanding that System.loadLibrary(fileName)
    automatically added the file to the library path for
    the individual program in question. If this is not
    the case, could you please elaborate a bit on adding
    it to the path?
    No, in effect it searches the path to find the dll library. You need to (re-)read the tutorial -
    http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step5.html

  • Jni library loaded by System.load fails on later call to System.loadLibrary

    I'm attempting to use jnotify to listen for directory modifications. This requires using jni to dynamically link to a c library. I have gotten everything to work successfully if I put the library on the java.library.path. However, I would prefer to let my application specify the full path to the jnotify library. My understanding is that I should be able to do a System.load("/foo/libjnotify.so") in a static block and then subsequent calls to System.loadLibrary("jnotify") should do nothing as the library is already loaded. However I am getting a 'Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path'. Am I misunderstanding the correct usage of these System calls?

    Joe wrote:
    That makes sense.
    The System.loadLibrary portion is in a 3rd party library which I am legally not allowed to change.
    Are there any other possible ways to accomplish the loading without the library being on the java.library.path?
    You have two problems - not one.
    The library itself is calling loadLibrary(). The standard idiom is that one does that in a static block. If a static block throws an exception, any exception, then the class will not load.
    Presumably the library is not checking for a duplicate library load. So your problem is that that loadLibrary() call must not throw an exception.
    Thus you cannot preload the library.
    Far as I can see you have the following options.
    - Put it on the path.
    - Create a jave exec handler (via Runtime.exec or jni), put the library on that path before you start another VM which does the real work.
    - Modify the java API loadLibrary() call so it catches the dup exception, that of course requires a boot option.

  • UnsatisfiedLinkError System.loadLibrary Windows CE JNI

    I am writing a java application for a Siemens SIMpad SL4 (Windows CE 3.0,Jeode EVM 1.9)
    I have a dll (mylib.dll) compiled with embedded visual c++ containing native functions.
    It is placed in the \windows directory.
    When I try to load the dll with System.loadLibrary(), I allways get an java.lang.UnsatisfiedLinkError.
    Things I have tried:
    System.loadLibrary("mylib");
    System.loadLibrary("mylib.dll");
    System.loadLibrary("\\windows\\mylib");
    System.loadLibrary("\\windows\\mylib.dll");
    java -Djava.library.path=\windows ...
    Different Directories for the dll (\windows, \, \windows\lib)
    Using other "CLASSPATH".
    Using other "PATH".
    But nothing worked.
    When I load a system dll (e.g. smartcard.dll) with System.loadLibrary("smartcard"), the dll
    is loaded succesfully. Only "self-compiled" libraries are not loaded.
    When I load the dll from a c++ test programm(HINSTANCE handle = LoadLibrary(L"mylib"))
    my library is loaded sucessfully.
    So it seems to be a java only problem.
    Any Ideas ?
    Thanks

    I tried to load different dlls with System.loadLibrary() and used the -verbose option of the jvm.
    A preinstalled dll: System.loadLibrary("winscard"); (Which has nothing to do at all with JNI)
    The "verbose" said: [Loaded Library \Windows\bin\winscard.dll]
    So the library seems to load succesfully.
    Another preinstalled dll: System.loadLibrary("finance");
    The "verbose" said: [Loaded Library \Windows\bin\finance.dll]
    The library loaded ok as well.
    A non exisiting dll: System.loadLibrary("nothing");
    The result was a "java.lang.UnsatisfiedLinkError nothing.dll; library not found"
    An empty test dll created with the dll wizard of embedded visual c++: System.loadLibrary("empty");
    (The dll is in the \Windows directory)
    The result was a "java.lang.UnsatisfiedLinkError empty.dll; library not found"
    A selfmade "JNI" dll: System.loadLibrary("mylib");
    The result is again a "java.lang.UnsatisfiedLinkError mylib.dll; library not found"
    So I don't think it's a problem with the method names.
    Thanks anyway.

  • Where to perform System.loadLibraryI()

    I have a Java web app that uses JSPs and servlets. The JSPs use an object that needs a DLL loaded through System.loadLibrary().
    When I put the code into the object's static initializer, I get an "Another loader has already loaded this library" exception.
    First of all, the javadocs say that this function doesn't throw an exception if the library is already loaded.
    Second of all, where is a good place to load this DLL?
    Brett Slocum
    [email protected]

    P.S. I've tried putting the loadLibrary() call in the init() of a servlet in the system, but then I get a "library not loaded" message in the JSP.

  • System.loadLibrary works in 1.3.1 but not in 1.2.2

    I Have a basic hello world application on Sun Solaris 7 that calls C++ from Java using JNI.
    The code works well on 1.3.1, but when I recompile it under 1.2.2 and run I get the following exception when I call System.loadLibrary to load my shared library:
    java.lang.UnsatisfiedLinkError: no MyLib in java.library.path
    My LD_LIBRARY_PATH is set correctly since it worked under 1.3.1.
    Just in case, I used the following code to get and set the java.library.path to no avail.
    // Check System properties
    String strLibPath = System.getProperty("java.library.path");
    System.out.println("The Lib Path before set == " + strLibPath);
    StringBuffer strLibPathBuffer = new StringBuffer("/u/kbonacc/mypath:");
    strLibPathBuffer.append(strLibPath);
    System.setProperty("java.library.path", strLibPathBuffer.toString());
    strLibPath = System.getProperty("java.library.path");
    System.out.println("The Lib Path after set == " + strLibPath);
    Are there any differences between 1.3.1 and 1.2.2 in this respect?
    Thanks,
    -- Ken

    In the bug parade I've heard excuses from Sun programmers that this is a read-only property and isn't supposed to be changed. It probably took them longer to write the reply to the bug than it would have to fix the code.
    I looked at the source code for the ClassLoader and for the source release of the JDK 1.3.1 and here's the code I found in the ClassLoader.loadLibrary() method:
            if (sys_paths == null) {
                    usr_paths = initializePath("java.library.path");
                    sys_paths = initializePath("sun.boot.library.path");
            }It seems it parses and caches the system and user library paths on startup and then never bothers to check them to see if they've changed ever again. I think it would be pretty simple to rewrite that code block by moving one line of code down two lines as this:
            if (sys_paths == null) {
                    sys_paths = initializePath("sun.boot.library.path");
            usr_paths = initializePath("java.library.path");I mean, it's not as if loadLibrary is really performance intensive or even critical enough to bother caching at all!
    This one code change could fix a lot of headaches.
    The particular headache I'm working on is that there doesn't seem to be any support in the Servlet 2.2 or 2.3 specification for JNI files. I'd really love to be able to use a directory like WEB-INF\jni to store libraries that need to be distributed with my web application. I tried to dynamically change java.library.path to include WEB-INF\jni, but alas I ran into the same problem you did, it doesn't work.
    Is is possible for this to be fixed, ever? I think it would take longer to say no and make up a reason why not then it would to actually make the fix... seems a good enough arguement to do it to me.
    And alternately, can we come up with a standard place to put JNI stuff for web applications in the next Servlet standards?
    Thanks in advance!
    -J.C.
    [email protected]

  • System.LoadLibrary + dlopen -- callback causes unresolved symbol

    Hi guys,
    I am currently trying to use the API
    System.loadLibrary(String name)in order to dynamically link shared libaries to SOLARIS JVM.
    I am facing some unresolved symbol at run-time .
    I load a shared library libhello1 (using system.LoadLibary)
    and I call from this lib (via JNI interface) a method which
    loads a second library libhello2(using dlopen) and invokes hello2().
    hello2 will call back a method hello_bug which is implemented in libhello1.
    There is the a mutual or cyclic dependence. This dependance is correctly handled if I link the libhello1 to a standard C implemented executable.
    But if I load libHello1 via System.Load, the second lib is correctly loaded but the call back is not possible due to unresolved symbol.
    It seems like the symbols are not kept in this case(or the dlopen creates a different thread?...)
    The workaround to fix the issue is to link explicitely libHello1 to libHello2 when building libHello2.
    I don't know if this is clear to everyone so
    I have reproduced this on a very simple case.
    Basicaly, I have implemented in standard C language 2 shared libraries:
    libHelloModule1.so, libHelloModule2.so
    one standard executable and one java interface to call the method
    Below is the full code for reproduce:
    hello1.h:
    #include <dlfcn.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <jni.h>
    #include "hello_jni.h" [u]//automatically generated by javah -- ref Makefile[/u]
    extern "C"  void hello_bug();
    hello1.cc :#include "hello1.h"
    extern "C" {
    JNIEXPORT void JNICALL Java_com_helloworld_Hello_ShowMessage
      (JNIEnv *, jobject, jstring){
    void *handle;
    const  char *error;
    void  (*init) (void);
    printf(" load Hello2 \n");
    handle = dlopen ("libHelloModule2.so", RTLD_LAZY);
    printf (" lib Hello2 onload.. \n");
    error = dlerror();
    if (!handle) {
          printf ("lib HelloModule2 not loaded correctly %s \n", error);
          exit(1);
       dlerror();
       init =(void(*)())  dlsym(handle, "hello2");
      error = dlerror();
            if(error)
                    fprintf(stderr, "Could not find print_hello(): %s\n",
    error);
                    exit(1);
    (*init)();
        dlclose(handle);
    void hello_bug()
    printf ("Hello bug correctly  invoked : CQFD\n");
    }// extern "C"
    hello2.cc
    #include "hello1.h"
    typedef void  ( *PF1) (char *, char *);
    extern "C" {
    void hello2(){
    printf ("Hello2 : ping Hello1\n");
    /*simple call work in c not via JNI*/
    hello_bug();
    Hello.java :
    package com.helloworld;
    import java.util.*;
    import java.io.*;
    public class Hello  {
      private native void ShowMessage(String msg);
      public void initialized() {
                System.out.println(" ShowMessage - called");
      try {
              ShowMessage("Generated with JNI");
           } catch (Exception e ) {
                e.printStackTrace();         }
      public Hello(){
      System.loadLibrary("HelloModule1");
                System.out.println(" HelloModule1 loaded");
    TestLocal.java :
    import java.util.*;
    import java.io.*;
    import com.helloworld.Hello;
    public class TestLocal{
    public TestLocal(){
            System.out.println("test local");
    public static void main(String[] args) {
            TestLocal test_local = new TestLocal();
            Hello test = new Hello();
            test.initialized();
    }THE MOST IMPORTANT IS IN THE MAKEFILE:
    Makefile :all: Hello.jar hello_jni.h libHelloModule1.so libHelloModule2.so TestLocal.class dummy
    Hello.jar: com/helloworld/Hello.class
    jar cvf $@  com/helloworld
    com/helloworld/Hello.class: Hello.java
    $(JAVAC)  -d . Hello.java
    hello_jni.h: Hello.jar
    $(JAVAH) -jni -o $@ -classpath ./Hello.jar com.helloworld.Hello
    libHelloModule1.so : hello_jni.h hello1.o  
    gcc  -G  -o $@ hello1.o -lstdc++
    libHelloModule2.so : hello2.o
    gcc   -G  -o $@ hello2.o -Wl -lstdc++  -L. -lHelloModule1   [u] # -->CASE  1 :THIS WORKS [/u]
    gcc   -G  -o $@ hello2.o -Wl -lstdc++ [u] #-->CASE 2 :THIS  DOES NOT WORK[/u]
    dummy : dummy_main.o
    gcc  -o $@ dummy_main.o -L. -lHelloModule1 -L/usr/local/lib -lstdc++
    hello2.o : hello2.cc
    gcc -I. -O -c  hello2.cc
    hello1.o : hello1.cc
    gcc -I. -O -c  hello1.cc
    TestLocal.class : TestLocal.java
    $(JAVAC) -classpath  . -d . TestLocal.java
    dummy_main.o :  dummy_main.cc
    gcc -I. -O -c  dummy_main.cc
    clean:
    rm -rf com *.o *.so *.class *.jar hello_jni.h dummyCASE 1 : libHelloModule1.so is explicitely linked to libHelloModule2
    myhost % dummy
    load Hello2
    lib Hello2 onload..
    Hello2 : ping Hello1
    Hello bug correctly invoked : CQFD
    myhost % java -cp . TestLocal
    test local
    HelloModule1 loaded
    ShowMessage - called
    load Hello2
    lib Hello2 onload..
    Hello2 : ping Hello1
    Hello bug correctly invoked : CQFD
    CASE 2 : libHelloModule1.so is not explicitely linked to libHelloModule2
    myhost % dummy
    load Hello2
    lib Hello2 onload..
    Hello2 : ping Hello1
    Hello bug correctly invoked : CQFD
    myhost % java -cp . TestLocal
    test local
    HelloModule1 loaded
    ShowMessage - called
    load Hello2
    lib Hello2 onload..
    lib HelloModule2 not loaded correctly ld.so.1: java: fatal: relocation error: file ./libHelloModule2.so: symbol hello_bug: referenced symbol not found
    My concern is to have this working in CASE1 with the JNI interface the same way it does in standard C built runtime.
    So does any have encountered this?
    Is there something I missed somewhere?
    Thanks lot for your help
    Youss

    Hi,
    I have implemented JNative which seems to be close to your problem.
    It works under Windows and Linux, and loads libraries via dlopen and dlsym.
    You can have a look at it's implementation at http://jnative.cvs.sourceforge.net/jnative/JNativeCpp/
    Don't forget to load your libraries before trying to call them with System.load("/path/to/your/lib.so"); if they are not referenced by LD_LIBRARY_PATH.
    This post may be false since I know nothing about Solaris. Perhaps JNative may be ported under Solaris ?
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error with System.loadLibrary("msvcr80");

    Hi,
    I am trying to test a library somebody wrote and that library is using msvcr80.dll
    So in my little java test program goes like this:
    try {
         System.loadLibrary("advapi32");
         System.loadLibrary("msvcr80");
         // code removed for simplicity
    } catch (UnsatisfiedLinkError e) {
         System.err.println("Library failed to load.\n" + e);
    }But I always get an exception when trying to load msvcr80:
    Runtime Error!
    Program: C:\Program Files\Java\jre6\bin\javaw.exe
    R6034
    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.
    What's the problem? The DLL can be found no problem (it's in the path pointed by java.library.path) but cannot be loaded. Is there another DLL that needs to be loaded beforehand besides advapi32?
    Thanks.

    Symbul wrote:
    Hi,
    Yes I know winsxs is not in the PATH, but I put it there just for test purposes. By the way I get the same C runtime javaw.exe error when I try to load ANY library that has a dependency on MSVCR80 (even microsoft DLLs, 3rd party JNI, etc.) and I'm not the only one in the office that has the problem either. Using Process Explorer I can see all the DLLs (every location) that are load by each applications and there is only one that's in memory and it's the correct one, so I'm quite puzzled as what could be wrong here.
    1. This is a JNI forum which this obviously is about.
    2. Please tell us what the problem is rather than asking why your solution doesn't work.
    3. Post the actual exception.
    4. And verify that you are NOT using windows 7, nor any 64 bit VM.
    Normally the MSVCR80 dll would be loaded dynamically by the OS when the reference of some other library requested it. In this case the most likely reason is because the dependent library (or some other) is not in the shared library path.

  • Catching System.loadLibrary exceptions

    I looked at the JNI book examples, and none does that. So i conclude that it is better to let that exception propagate up the stack. It makes sense because otherwise class behavior would be undefined. If you have evidence to the contrary, please speak up.
    Thanks.
    chap2/HelloWorld/HelloWorld.java- static {
    chap2/HelloWorld/HelloWorld.java: System.loadLibrary("HelloWorld");
    chap2/HelloWorld/HelloWorld.java- }
    chap2/HelloWorld/HelloWorld.java-}
    chap3/IntArray/IntArray.java- static {
    chap3/IntArray/IntArray.java: System.loadLibrary("IntArray");
    chap3/IntArray/IntArray.java- }
    chap3/IntArray/IntArray.java-}
    chap3/IntArray2/IntArray.java- static {
    chap3/IntArray2/IntArray.java: System.loadLibrary("IntArray");
    chap3/IntArray2/IntArray.java- }
    chap3/IntArray2/IntArray.java-}
    chap3/ObjectArrayTest/ObjectArrayTest.java- static {
    chap3/ObjectArrayTest/ObjectArrayTest.java: System.loadLibrary("ObjectAr
    ayTest");
    chap3/ObjectArrayTest/ObjectArrayTest.java- }
    chap3/ObjectArrayTest/ObjectArrayTest.java-}
    chap3/Prompt/Prompt.java- static {
    chap3/Prompt/Prompt.java: System.loadLibrary("Prompt");
    chap3/Prompt/Prompt.java- }
    chap3/Prompt/Prompt.java-}
    chap3/Prompt2/Prompt.java- static {
    chap3/Prompt2/Prompt.java: System.loadLibrary("Prompt");
    chap3/Prompt2/Prompt.java- }
    chap3/Prompt2/Prompt.java-}
    chap4/InstanceFieldAccess/InstanceFieldAccess.java- static {
    chap4/InstanceFieldAccess/InstanceFieldAccess.java: System.loadLibrary("
    nstanceFieldAccess");
    chap4/InstanceFieldAccess/InstanceFieldAccess.java- }
    chap4/InstanceFieldAccess/InstanceFieldAccess.java-}
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java- static {
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java: System.loadLibrary(
    InstanceFieldAccess");
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java- }
    chap4/InstanceFieldAccess2/InstanceFieldAccess.java-}
    chap4/InstanceMethodCall/InstanceMethodCall.java- static {
    chap4/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
    tanceMethodCall");
    chap4/InstanceMethodCall/InstanceMethodCall.java- }
    chap4/InstanceMethodCall/InstanceMethodCall.java-}
    chap4/InstanceMethodCall2/InstanceMethodCall.java- static {
    chap4/InstanceMethodCall2/InstanceMethodCall.java: System.loadLibrary("I
    stanceMethodCall");
    chap4/InstanceMethodCall2/InstanceMethodCall.java- initIDs();
    chap4/InstanceMethodCall2/InstanceMethodCall.java- }
    chap4/InstanceMethodCall2/InstanceMethodCall.java-}
    chap4/MyNewString/MyNewString.java- static {
    chap4/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
    chap4/MyNewString/MyNewString.java- }
    chap4/MyNewString/MyNewString.java-}
    chap4/MyNewString2/MyNewString.java- static {
    chap4/MyNewString2/MyNewString.java: System.loadLibrary("MyNewString");
    chap4/MyNewString2/MyNewString.java- }
    chap4/MyNewString2/MyNewString.java-}
    chap4/StaticFieldAccess/StaticFieldAccess.java- static {
    chap4/StaticFieldAccess/StaticFieldAccess.java: System.loadLibrary("Stat
    cFieldAccess");
    chap4/StaticFieldAccess/StaticFieldAccess.java- }
    chap4/StaticFieldAccess/StaticFieldAccess.java-}
    chap4/StaticMethodCall/StaticMethodCall.java- static {
    chap4/StaticMethodCall/StaticMethodCall.java: System.loadLibrary("Static
    ethodCall");
    chap4/StaticMethodCall/StaticMethodCall.java- }
    chap4/StaticMethodCall/StaticMethodCall.java-}
    chap5/MyNewString/MyNewString.java- static {
    chap5/MyNewString/MyNewString.java: System.loadLibrary("MyNewString");
    chap5/MyNewString/MyNewString.java- }
    chap5/MyNewString/MyNewString.java-}
    chap6/CatchThrow/CatchThrow.java- static {
    chap6/CatchThrow/CatchThrow.java: System.loadLibrary("CatchThrow");
    chap6/CatchThrow/CatchThrow.java- }
    chap6/CatchThrow/CatchThrow.java-}
    chap6/InstanceMethodCall/InstanceMethodCall.java- static {
    chap6/InstanceMethodCall/InstanceMethodCall.java: System.loadLibrary("In
    tanceMethodCall");
    chap6/InstanceMethodCall/InstanceMethodCall.java- }
    chap6/InstanceMethodCall/InstanceMethodCall.java-}
    chap6/ThrowByName/ThrowByName.java- static {
    chap6/ThrowByName/ThrowByName.java: System.loadLibrary("ThrowByName");
    chap6/ThrowByName/ThrowByName.java- }
    chap6/ThrowByName/ThrowByName.java-}
    chap8/NativeString/NativeString.java- static {
    chap8/NativeString/NativeString.java: System.loadLibrary("NativeString")
    chap8/NativeString/NativeString.java- }
    chap8/NativeString/NativeString.java-}
    chap9/OneToOne/OneToOne.java- static {
    chap9/OneToOne/OneToOne.java: System.loadLibrary("OneToOne");
    chap9/OneToOne/OneToOne.java- }
    chap9/OneToOne/OneToOne.java-}
    chap9/OneToOne/OneToOne.java-
    chap9/SharedStubs/CPointer.java- static {
    chap9/SharedStubs/CPointer.java: System.loadLibrary("disp");
    chap9/SharedStubs/CPointer.java- SIZE = initIDs();
    chap9/SharedStubs/CPointer.java- }
    chap9/SharedStubs/CPointer.java-

    There are 2 choices, i guess:
    1) Catch and don't re-throw, thus allowing pure java methods to be called,
    even though native method calls will throw, and state might be undefined.
    2) Catch and don't re-throw: thus making all method calls on such a class
    to throw, since object instantiations will fail. But at least in this
    case, an object w/ undefined behavior won't be in use.
    And i guess one could choose one or the other based on circumstances. In
    my case, the class will pretty much be unworkable w/o native methods, so
    what would be the best choice?
    Looking at NetBeans source, i'm seeing 2 examples of 1, and 1 example of
    2. Both examples of 1 utilize fail-backs if library isn't found, such as
    not calling the native method involved. The example of 2, catches
    Exception but lets Throwables go thru, which means it doesn't catch
    UnsatisfiedLinkError, and NbDdeBrowserImpl is unusable it library isn't
    found. My situation is similar to this. I concluded for myself, that we
    should catch all 3 exceptions from System.loadLibrary, show error dialog
    w/ each exception's message, and re-throw each exception, because
    otherwise, 90% of methods in the class are going to throw, and there is no
    way to get any decent functionality out of it in such a situation. Would
    you agree w/ my conclusion?
    1.1)
    /tasklist/core/src/org/netbeans/modules/tasklist/core/Background.java
    private static void loadLibrary() {
    if (loadfailed) return;
    if (false == loaded) {
    try {
    // XXX be aware of #32080, that changes location of native
    libraries
    System.loadLibrary("tasklist_bgthreads"); // NOI18N
    loaded = true;
    } catch (Throwable t) {
    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, t);
    loadfailed = true;
    1.2)
    tasklist/timerwin/src/org/netbeans/modules/tasklist/timerwin/AlwaysOnTop.java:
    try {
    setAlwaysOnTopMethod = Window.class.getDeclaredMethod(
    "setAlwaysOnTop", // NOI18N
    new Class[] {Boolean.TYPE});
    } catch (Throwable t) {
    // ignore
    if (setAlwaysOnTopMethod == null) {
    try {
    System.loadLibrary("alwaysontop"); // NOI18N
    libLoaded = true;
    } catch (Throwable t) {
    libLoaded = false;
    2) extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
    try {
    if (org.openide.util.Utilities.isWindows()) {
    // should be 32 or 64 bit, but it may not be present on
    some jdks
    String sunDataModel =
    System.getProperty("sun.arch.data.model"); //NOI8N
    if (sunDataModel != null) {
    if ("64".equals(sunDataModel)) { //NOI18N
    System.loadLibrary(EXTBROWSER_DLL_64BIT);
    } else {
    System.loadLibrary(EXTBROWSER_DLL);
    } else {
    String javaVMName =
    System.getProperty("java.vm.name"); //NOI8N
    if ((javaVMName != null) && (javaVMName.indexOf("64")
    -1)) { //NOI18NSystem.loadLibrary(EXTBROWSER_DLL_64BIT);
    } else {
    System.loadLibrary(EXTBROWSER_DLL);
    } catch (Exception e) {
    DialogDisplayer.getDefault ().notify (
    new
    NotifyDescriptor.Message(NbBundle.getMessage(NbDdeBrowserImpl.class,
    "ERR_cant_locate_dll"),
    NotifyDescriptor.INFORMATION_MESSAGE)
    }

  • System.loadLibrary Hangs

    I have a .dll used for address verification and I wrote a JNI wrapper .dll in C++ so I could use it with my application. I wrote a class with both a main method and constructor method and the class works fine at the command prompt. When I try to use the class with my application it hangs at the System.loadLibrary command. I'm using JRun 4 on a Win 2k server. I set the java.library.path to the location of the .dll and made sure all necessary files were in that folder. Any helpful suggestions would be appreciated. Thanks.

    A hang at that point in time means it has nothing to do with java.
    The dll probably has a dllmain method (or whatever it is called.) That method is being called and is never returning. You need to figure out why.

  • System.loadLibrary() for libraries with dependencies?

    Hi,
    Given an application that depends upon JNI library "jniLibrary.dll" which in turn depends upon "otherLibrary.dll" when one invokes System.loadLibrary("jniLibrary") two things happen:
    1) Under normal applications, the system will complain it can't find dependent library "otherLibrary" because it isn't in the PATH. You can work around this by invoking System.loadLibrary("otherLibrary") first but I've been told System.loadLibrary() is only meant for JNI libraries and invoking it on any other library is not guaranteed to work.
    2) Under Webstart applications, if you try loading "otherLibrary" first it will fail because of http://bugs.sun.com/view_bug.do?bug_id=6191612
    There doesn't seem to be a "correct" way to fix this problem under all environments. Can someone please explain what the application should be doing in this case to ensure that "jniLibrary" loads correctly? Modifying the PATH is not an option because of the Webstart use-case (besides which, users don't appreciate it).
    Thank you,
    Gili

    2) Under Webstart applications, if you try loading "otherLibrary" first it will fail because of http://bugs.sun.com/view_bug.do?bug_id=6191612
    That is a little weird.
    Far as I know you can't stop the OS from loading dependent libraries. Thus when the OS attempts to load library B, if it explicitly depends on library A then the OS (not java) will attempt to load it.
    Now if the OS can't load it then it will throw a system exception.
    So the only way that bug makes sense is if the jws is parsing the shared library to find dependencies and then checking the process space for them and throwing if they are not there. Seems like a lot of work. When it could just load it. (But maybe it is actually loading them from another source)
    At any rate that isn't what that bug says. It says that if you don't in fact load library A, then it will fail. So load it.I filed that bug so I'll try filling in the holes.
    Problem 1: Webstart uses a custom ClassLoader that only unpacks DLLs from their JAR file on-demand. So if you try loading A the class-loader will extract it from the JAR file into a temporary directory and invoke win32's LoadLibrary on it. Of course it will never find any dependent libraries because they haven't been extracted.
    Problem 2: If you use a manifest file (also packed in the JAR file) you have no way to tell Webstart to unpack it alongside the DLL. Loading the DLL without it will fail.
    If I remember correctly (this is off the top of my mind) you can work around problem #1 by loading the dependent libraries first but this won't work if you have circular dependencies. You can work around problem #2 by embedding the manifest file into the DLL file. I'm fairly sure I tried working around #1 as mentioned but it still broke (maybe another problem beyond circular dependencies that I don't recall).
    This is a lot of cryptic work one needs to do just to get things up and running. We're spending most of our time trying to hack the JVM to do what we want instead of it doing what we mean (the spirit of System.loadLibrary()).

  • System.loadLibrary in SunOne Debug

    How do I add a new JNI library file to the debug library path so I can use it for debugging?

    Your DLL files must be packages in a Jar file not on the client's file system. The JAR must also be specified in your JNLP file with the nativelib tag in the resources section.
    When you call System.loadLibrary() do not include the .dll extension (I learned this one the hard way today).

  • System.loadLibrary() and DLL manifest files

    Hi,
    Has anyone gotten Java WebStart working with VisualStudio 2005 DLL manifest files? That is, it is illegal to load DLLs without having the manifest file visible. Last time I checked, Webstart did not extract native DLLs from JARs until System.loadLibrary() was used -- but this would not work for manifest files.
    The only workaround I can think of is embedding the manifest files inside the DLL but this sounds a bit ugly.
    A related problem is that if I System.loadLibrary() on library A and it depends on library B which I have never loaded before then this will fail because Webstart did not extract B.
    This is related to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6191612
    Any ideas?
    Gili

    The dll is
    deployed as part of a J2EE application, and shouldn't
    need registering by the regsvr32 program.regsvr32 should have nothing to do with JNI dlls. Unless the dll is also a COM object factory (or what ever the proper name for such a thing is), then regsvr32 should make no difference to its operation.
    >
    Can anyone explain the difference between the load()
    and loadLibrary() methods in detail?They do the same thing, except that for load() you specify the full path to the object and with loadLibrary() you just give its base name and the runtime tries to find it in the java.library.path after adding ".dll" to the name.
    You should only call one or the other. Calling both would be an error.

  • Compilation and System.loadLibrary

    Hi everybody,
    I'm pretty sure this will be the last time I talk about System.loadLibrary issues. This is definitely just a concept question, no code or JNI needed.
    I have a call to System.load library like this:
    System.loadLibrary( "Class" );
    and then directly after that, a I call a constructor for the class:
    Class c = new Class( params );
    The problem is, though, that the code won't compile. I know the constructor is right, and I've looked at the System.loadLibrary documentation, and I can't figure out what the problem is. I know System.loadLibrary is a runtime event, and I'm using Eclipse, if that makes any difference.
    So, I guess here comes the question finally. How can I make the compiler realize that the class I'm loading with System.loadLibrary is legitimate, so it doesn't give me a compiler error?
    Thanks,
    Jezzica85

    jezzica85 wrote:
    Oh, I'm sorry. That was just a general example, and yes, "Class" was just a fill-in for what I actually named the class, and "params" a fill-in for the parameters. I figured the specifics weren't important. I guess I should have made that example clearer.
    Jezzica85I just wanted to make sure.
    So, you have a class called whatever you have there in your classpath, and you've verified that it has a public constructor with the same parameters that you have given it? If both those statements are true then I don't see how you can have a compiler error involving the ctor - please post a copy and paste of the exact compiler error message.

  • How to Load 2 library files using System.loadLibrary in one .java file!!!

    Hello,
    Someone please help me. What I am trying to do is load two .DLL files in my program. Program works fine when I
    do the following way i.e. I have two .java files and in each I am loading one .DLL file. But I don't want to have
    two .java files I want to load both the .DLL files in one program.
    **************** Example.java **********
    import java.io.*;
    import java.util.*;
    public class Example
    public native int A(String in);
    static
    System.loadLibrary( "API2" );
    public static void main( String args[])
         Ex ex = new Ex();
         int r;
         r = ex.A("TEST");
    public Example()
    *****************Ex.java*****************
    public class exsysml
    public native int A(String in);
    public exsysml()
    System.loadLibrary("API3");
    The above way works. But I need only one .java file to load both the .DLL files. i.e.
    import java.io.*;
    import java.util.*;
    public class Example
    public native int A(String in);
    static
    System.loadLibrary( "API2" );
    System.loadLibrary( "API3" );     
    public static void main( String args[])
         Example ex = new Example();
         int r;
         r = ex.A("TEST");
    public Example()
    but when I do this way it doesn't work and I get a UnSatisfiedLinkage Error at ex.A("TEST"). While doing the top way it works.
    How can I fix this to just have one .java file and load both the library files as done in the bottom program but doing this program doesn't work. Any help is appreciated.
    Thanks!

    what I figured out so far is that we can only load one library file in a single class and define all the native methods present in that library in the class where we are loading it. Means we can't load multiple library files in a single class. It's just my thought else if someone provides a better solution. I may be wrong so that's why I need your help.
    Thanks

Maybe you are looking for