0

I have a dll (let's name it Sample.dll) that is being called by a Java application thru JNA. The said dll locates a file inside a folder named "Data". I think the said dll was loaded successfully since there was no error message being returned. Below is the code to load the dll:

sampleLibrary = (SampleLibrary)Native.loadLibrary("Sample", SampleLibrary.class);

After execution of that code, a native method is called to open a session. This method accepts the path of a folder as a parameter.

sampleLibrary.openSession(path);

The JNA cannot seem to locate the file since the error is being returned that says the file does not exist. I try to set and print the "user.dir" and the "java.library.path" to see if the path being passed is correct.

System.setProperty("java.library.path", "C:/Sample");
System.out.println("user.dir property: " + System.getProperty("user.dir"));
        System.out.println("java.library.path property: " + System.getProperty("java.library.path"));

These return the working directory where the jar, dll and a Data folder are located.

File Structure:

C:\Sample
  \-- SampleJna.jar
  \-- Sample.dll
  \-- Data 
      \----- some files
JoshDM
  • 4,939
  • 7
  • 43
  • 72
user123456
  • 73
  • 1
  • 8

1 Answers1

0

First, the .loadLibrary is being deprecated. Try the Native.load() instead. Sample below as stated here:

SampleLibrary INSTANCE = (SampleLibrary) Native.load((Platform.isWindows() ? "Sample" : "c"), SampleLibrary.class);

Second, in your project properties under the VM Options (if you are using Netbeans), make sure the library path is declared like so: -Djna.library.path=C:\Sample\

If you still get some error, please post your stacktrace so everyone can check.

akatsuki
  • 27
  • 8