11 Replies Latest reply: Jan 16, 2007 5:50 AM by 843802 RSS

    (JNI) UnsatisfiedLinkError Native Library already loaded in Applet

    843802
      I read that JNI is only allowed to load a native libary once, i have two applets, both need that libary, however when i load them in different browser windows the second applet which is loaded cant access the dll and gets the above error. If i run the second applet in the first browser window it works fine.

      I tryed
      System.gc();
      System.runFinalization();
      System.loadLibrary("libary");

      but it didnt help. I read that you can place the class which does the JNI calls into the classpath but how is that possibil if it is an applet from a server... It is only in the /cache directory of the browser i guess, how can i add my class to the classpath ?

      Or is there any other way around this problem ? (except using multiple dlls)

      Thanks
        • 1. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
          843802
          There are two ways we have figured to fix the problem you are having.

          1) Is there any way you can combine the two applets? Set a flag for which classes are needed by who called the applet...did that make sense?

          If you combine the two applets into one, your dll loads in the classloader, therefore, your are running one session and will have no problem with the dll having to load twice.

          2) Have a setup applet that loads the dll as the page loads. Set your other two applets so that the do not need to use the dll.

          Can you tell me what the functionality of your applets are?
          • 2. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
            843802
            Thanks for your reply =)

            Well, i doesnt matter if i put my code in two or one applet the problem remains, i only said it to get it more clear.

            The same applet will NOT run in another browser window, because the dll is already loaded. The java plugin uses another classloader for the very same applet in another browser window.

            I already have a class that does the dll loading and method calling, the loading is static but that doesnt matter because i cant call methods from another browser window. Its like having one VM for each browser window, you have to init the dll for each browser window, but since the dll has been already loaded through JNI by one classloader you cant use it in another browser window.

            My dll does calls to a windows services, i found this

            http://developer.java.sun.com/developer/bugParade/bugs/4225434.html

            So that explain why, but there is no work around and shared classloaders, im not familar with.
            • 3. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
              843802
              I've got a workaround now. Its not that bad, what i
              did was seperate the class which calls the dll. It has its own jar now,
              this jar file
              is now installed on the client machine and i added it to the classpath of
              the java plugin. Now i am able to call this class within my browser and i
              dont have any problems with the dll anymore.

              The only bad thing about this is, that i have to modify the property file
              of the java plugin in every user_home dir to add a customer line as
              startup parameter, the classpath of my jar file that is. (because system
              classpath != java plugin classpath)
              • 4. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                843802
                I found that Oracle's JInitiator WILL ALLOW page reloads
                for the same shared library as well as different pages using
                the same shared library. For those who need to use Sun's
                JRE 1.4, you'll need to (1) copy the "client" subdir
                as "hotspot" and (2) change the setting in JInitiator to point
                to that JRE base path. If Oracle can do it for Sun's product,
                why can't Sun do it for Sun's product.... embarrassing to say
                the least!
                • 5. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                  843802
                  Hi!
                  Your problems come out when the applet is loaded twice (for instance two copies from different servers or 2 different version of the same applet).
                  I've found a dirty hack that's to rename the native library and load it again.

                  There are two RFE on Sun JVM related to your issue. feel free to vote them:
                  System.unoladNative(): http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5075039

                  Allow a shared native library to be accessible by more than one classloader (applet): http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4750956
                  • 6. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                    843802
                    Hello
                    I am facing a problem like yours, I tried your suggestion, but I got AccessControlException while loading dll from the browser applet
                    please let me know how to solve this.
                    Harish
                    • 7. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                      843802
                      this is not the same problem.
                      Is the applet signed?
                      if it is load the native library from the init() method or load the dll in a privileged block (see AccessController and PrivilegedAction)
                      • 8. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                        843802
                        Thank you for the reply.

                        Let me explain the problem. I have a signed applet which loads a dll. Like all others in this thread I am also facing the "Library already loaded problem". I decided to take the suggestion of "ragwanka" posting No. 4 in this thread.

                        As per the suggestion I made a separate class to load the dll (called dllloader). I made a signed jar having dllloader. I put an entry in the java plugin classpath as suggested. From the actual applet I am trying to call the function in dllloader. At runtime I am getting the AccessControlException.

                        Please help. Thanks in advance.

                        Regards
                        Harish N S
                        • 9. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                          843802
                          I had this same problem and found a simple fix. All I did was move the .dll loading class to a separate jar. Then I install the jar into the ext folder during the plugin install process. This eliminates the problem with the already loaded dll and you won't have the security issues that you are seeing.
                          • 10. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                            843802
                            Hi,

                            I am very interested in JNI via JAVA applet, since it seems that it is the only way of running c-code on the client side. I have browsed the web quite extensively, and to my suprise only a few material is available to describe the needed steps to get the thing going.

                            I was wondering if you guys could post (or point me to if they exist) some tutorial code on this topic.

                            Thanks in advance,
                            • 11. Re: (JNI) UnsatisfiedLinkError Native Library already loaded in Applet
                              427038
                              here is how to NOT do it:
                              [http://forums.sun.com/thread.jspa?threadID=5420045|http://forums.sun.com/thread.jspa?threadID=5420045]

                              Can anybody explain / repair this?