12 Replies Latest reply on May 12, 2011 2:08 PM by Peter Johnson

    How to make Jboss server recognize Windows DLL

    Tuan Nguyen Newbie

      I was trying to call my Java code that uses JNA to link DLL's.

       

      In my class, I define jna.library.path as such:

      static {
      System.setProperty(“jna.library.path”, “C:\\Software\\VMWare\\VSphere-4.1″);
      }

      In Jboss’s start-up script. I set the JVM argument to to point to jna.library.path containing DLL’s
      set “JAVA_OPTS=%JAVA_OPTS% -Djna.library.path=C:\Software\VMWare\VSphere-4.1″

      When I run the code on Jboss server, I got a null pointer exception for the following code:

      hostHandle = new VixVSphereHandle(“10.2.0.100″,443,”administrator”,”cf@dp@$$w0rd”);

      It seems that Jboss could not find the DLL’s to link VixVSphereHandle.

      Environment:

      (1) Jboss 5.0.1

      (2) Windows Server 2003

       

      Any idea?

      Thanks,

      Tuan

        • 1. How to make Jboss server recognize Windows DLL
          Peter Johnson Master

          Is this a typo: “jna.library.path”? It should be jni.library.path. Also, it is ually better to set that on the ocmmandl ine when running the app server - you can add it to run.bat or run.conf.bat. In addition, make sure that the jni.library.path includes the directories required by any DLLs needed by your DLL. Usually, if the library is in your pATH, this should all just work since jni.library.path, if it is not set, defaults to PATH.

           

          Also, use the Properties MBean in the jmx-console to verify the setting on jni,library.path.

          • 2. How to make Jboss server recognize Windows DLL
            Tuan Nguyen Newbie

            This is not the typo. I actually use JNA (Java Native Access) to access shared libraries (DLLs on Windows) instead of JNI.

             

            I added the jna.librabry.path to conf.bat as follows:

             

            rem # Path to jna.library.path

            set "JAVA_OPTS=%JAVA_OPTS% -Djna.library.path=C:\Software\VMWare\VSphere-4.1"

             

            I also added this code to my class:

             

               static {

                           System.setProperty("jna.library.path", "C:\\Software\\VMWare\\VSphere-4.1");

              

               }

             

            When I run the program in Jboss, I still got the following error:

             

            java.lang.UnsatisfiedLinkError: Unable to load library 'vix': The specified module could not be found.

            2011-05-06 10:26:45,950 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)

            2011-05-06 10:26:45,950 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)

             

            It seems that JBOSS could not find the DLLs resulting to UnsatisfiedLinkError.

             

            BTW, I tested this code in Eclispe and it ran fine! Certainly, Eclispe and JBOSS are two different environments.

             

            Also, I could not find the properties MBean in JMX-Console.

             

            Please let me know what additional info is needed for debug purpose.

             

            Any help from the community is greatly appreciated!

             

            Tuan

            • 3. How to make Jboss server recognize Windows DLL
              Peter Johnson Master

              Post the code you use to load the library. Provide the value for all variables used in that code.

               

              Post the full path name of the library you are attempting to open. Also, do you know what other libraries your library depends on? The dependency walker can help you with that. (http://www.dependencywalker.com/) Are those libraries in the PATH? It could be that finding yoru library works just fine, but the loader fails because it can't find a library required by that library.

               

              (Even I had a typo, I meant java.library.path, not jna.library.path! )

              • 4. How to make Jboss server recognize Windows DLL
                Tuan Nguyen Newbie

                I dowloaded the utility, dependencywalker from http://www.dependencywalker.com and ran against the main vix.dll. I got the following errors:

                 

                (1) DEVMGR.DLL Error opening file: The system cannot file the find specified.
                (2) MSJAVA.DLL      Error opening file: The system cannot file the find specified.

                Warning: At least one delay-load dependency module was not found.

                 

                I used java.librabry.path instead of jna.library.path.

                Change in run.conf.bat:

                rem # Path to jna.library.path

                set "JAVA_OPTS=%JAVA_OPTS% -Djava.library.path=C:\Software\VMWare\VSphere-4.1"

                 

                Java code:

                import com.vmware.vim25.*;

                import com.vmware.vim25.mo.*;

                import com.vmware.vix.*;

                import com.vmware.vix.util.*;

                 

                    private static String user = "administrator";

                    private static String pwd = "cf@dp@$$w0rd";

                  static {

                 

                 

                              System.setProperty("java.library.path", "C:\\Software\\VMWare\\VSphere-4.1");

                   }

                 

                .......

                 

                public boolean vmCmpDeploy (String osType, String vmConfigPath) {

                 

                                VixVSphereHandle hostHandle = null;

                 

                 

                                String guser;

                                String gpwd;

                                String guestenvip;

                                VixError err;

                                OperatingSystems os;

                               

                                try {

                                         

                              if (osType.equalsIgnoreCase("Windows"))

                                        os = OperatingSystems.windows;

                              else if (osType.equalsIgnoreCase("Linux"))

                                        os = OperatingSystems.linux;

                              else if (osType.equalsIgnoreCase("Linux"))

                                        os = OperatingSystems.macintosh;

                              else

                                        os = OperatingSystems.valueOf("Solaris");

                             

                          //java.lang.UnsatisfiedLinkError: happens at this line          

                                    hostHandle = new VixVSphereHandle(vmURL, user, pwd);

                .......

                 

                Here's the error in the log:

                 

                2011-05-06 15:06:46,259 ERROR [STDERR] (WorkManager(2)-3) java.lang.UnsatisfiedLinkError: Unable to load library 'vix': The specified module could not be found.

                2011-05-06 15:06:46,259 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)

                2011-05-06 15:06:46,259 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.Library$Handler.<init>(Library.java:140)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.Native.loadLibrary(Native.java:379)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.sun.jna.Native.loadLibrary(Native.java:364)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.vmware.vix.VixLibrary.<clinit>(VixLibrary.java:52)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.vmware.vix.VixHandle.<init>(VixHandle.java:39)

                2011-05-06 15:06:46,275 ERROR [STDERR] (WorkManager(2)-3)           at com.vmware.vix.VixHandle.<clinit>(VixHandle.java:38)

                 

                Appreciate any help from Jboss community!

                 

                Tuan

                • 5. Re: How to make Jboss server recognize Windows DLL
                  Peter Johnson Master
                  (1) DEVMGR.DLL Error opening file: The system cannot file the find specified.

                  (2) MSJAVA.DLL      Error opening file: The system cannot file the find specified.

                  Where are these files located? Full paths please.

                  • 6. Re: How to make Jboss server recognize Windows DLL
                    Tuan Nguyen Newbie

                    Peter,

                     

                    The path for DEVMGR.DLL is C:\Windows\System32. Should I have Jboss referenced this path?

                     

                    I could not locate MSJAVA.DLL. I did global search but yield nothing!

                     

                    Thanks for your prompt response.

                     

                    Tuan

                    • 7. Re: How to make Jboss server recognize Windows DLL
                      Peter Johnson Master

                      If vix.dll needs msjava.dll, which it appears to, then if you don't have msjava.dll, it will never work.

                      • 8. Re: How to make Jboss server recognize Windows DLL
                        Tuan Nguyen Newbie

                        Peter,

                         

                        I'll try to locate the missing msjava.dll and retry it and see if it works. But I think you're right. The load failed because it could not find the DLLs mneeded for vix.dll, which caused java.lang.UnsatisfiedLinkError.

                         

                        Thanks,

                         

                        Tuan

                        • 9. Re: How to make Jboss server recognize Windows DLL
                          Tuan Nguyen Newbie

                          The missing MSJAVA.DLL is not critical according to the link below. That DLL is optional but not required.

                           

                          http://www.dependencywalker.com/faq.html

                          The other DEVMGR.DLL has been included in the PATH.

                           

                          I'm pretty much dead in the water as far Jboss & JNA integration!

                           

                           

                          Tuan

                           

                           

                          • 10. Re: How to make Jboss server recognize Windows DLL
                            Peter Johnson Master

                            Here is what I would try:

                             

                            a) Write a simple Java command line app that used JNA to load the vix.dll

                             

                            b) Use Process Monitor from sysinternals to see which what files ar actually being access.

                             

                            c) Get the source code for JNA and see if there is some detailed logging available to debug loading issues. If so, turn it on. If not, add logging code to it.

                             

                            Basically, you have to debug JNA and find out why it is not working correctly.

                            • 11. Re: How to make Jboss server recognize Windows DLL
                              Tuan Nguyen Newbie

                              Peter,

                               

                              Can you guide me a bit on (b)'s usage?

                               

                              Thanks,

                               

                              Tuan

                              • 12. Re: How to make Jboss server recognize Windows DLL
                                Peter Johnson Master

                                Set the filter to show only events from the process (pid) running JBoss AS. The easiest way to find the pid is to look for the java.exe process in Task Manager. If there are multiple such processes, you will have to determine which one is running JBoss AS - usually has a large memory footprint, also it helps if you can view the command line. Task Mangere for Server 2003 doesn't showthe command line, if I recall correctly, so you might need to get Process Explorer for sysyinteranls also - it will provide the command line used to start java.exe - look fo the org.jboss.Main class.

                                 

                                You might want to set a second filter that shows only file operations. Unfortunately, you can't set that as a single filter, but you can set the filter to remove events you don't care about. You don't need to filter out everything, just the really verbose stuff (that is, events that you don't care about but which happen quite often.

                                 

                                Once the filtering is set up, run your app which attempts to load the dll. Then see what files are being accessed, and whether it was successful or not.