0

Need to run Java class with VM arguments. I am trying loadLibrary(thirt party DLL) from Java Application. For that I need to set java.library.path jvm arguement. I have tried following approach.

"C:\Program Files (x86)\Java\jdk1.8.0_92\bin\java" -Djava.library.path=C:\DLL TestMyProgram

I am running 32 bit DLL on 64 bit AMD platform thats why specifying full 32 bit jdk path in above command.

Here while running I am getting below exception

java.lang.UnsatisfiedLinkError: TestMyProgram.group(Ljava/lang/String;Z)Ljava/lang/String;

Not sure why java.library.path is not preperly set by first command. Any help is greatly appreciated.

Here is my program

public class TestMyProgram {

    static
    {
        try {
            System.loadLibrary("mydll");
        } catch (UnsatisfiedLinkError e) {

            System.out.println("Library not loaded" + e);
        }
    }

    public static native String group(String msg, boolean isOracle);

    public static void main(String args[]) {

         StringBuffer sb = new StringBuffer();

         sb.append("mymessage");

         System.out.println("input \n : " + sb.toString());
         String outStr = group(sb.toString(), false);

         System.out.println(new Date());

         System.out.println(outStr);

         System.out.println(new Date());
    }
}
DeepInJava
  • 1,871
  • 3
  • 16
  • 31
  • If you don't see your `Library not loaded` trace, it looks like the DLL is loaded. Exception message seems to imply the suitable entry point is not found in the dll. Did you export it? Does it have the correct signature? – cma Sep 14 '16 at 11:45

1 Answers1

0

If the exception is throwed from String outStr = group(sb.toString(), false);, you should verify the native API is implemented and exported in mydll.dll.

Execute dumpbin /exports or other similar tools could help on this. Here is a output sample:

S:\path>dumpbin /exports mydll.dll
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file mydll.dll

File Type: DLL

  Section contains the following exports for mydll.dll

    00000000 characteristics
           0 time date stamp Thu Jan 01 08:00:00 1970
        0.00 version
           1 ordinal base
           ? number of functions
           ? number of names

    ordinal hint RVA      name

         49    0 0001599C JNI_OnLoad
         48    1 00015C60 JNI_OnUnload
         14    2 0000???? Java_TestMyProgram_group

If Java_TestMyProgram_group is not listed in the output, the method is not exported of implemeted in mydll.dll.

Beck Yang
  • 3,004
  • 2
  • 21
  • 26