This problem is a famous one and there are many similar questions but no solution helped me. So please, don't mark my question as duplicate.
I developed a small application in Java that uses external dlls. Everything seems to be working fine in eclipse but once I export to runnable jar and run using java -jar myapplication.jar
, it throws the following exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Testing.dal.LoggingAccess.__LoggingAccess0(Lnet/sf/jni4net/inj/IClrProxy;Ljava/lang/String;)V
at Testing.dal.LoggingAccess.__LoggingAccess0(Native Method)
at Testing.dal.LoggingAccess.<init>(LoggingAccess.java:25)
at Program.listItems(Program.java:32)
at Program.main(Program.java:27)
I have tried to do almost all what is suggested in other answers but unfortunately nothing worked for me. I tried to set java.library.path
, but I don't know if i'm doing it correctly. I'm not a java developer and java world is totally new to me. So I may be doing it in the wrong way. It would be great if you can give me any hint on how to solve this.
I was able to solve this problem myself.
The needed library was in the correct place but I had to reference it in the java project. The problem is that i don't want to play around with Path (environment variables) or copy the libraries to the system32 folder as suggested in many posts. Thats why i added System.Laod(new java.io.File("path to the dll").getAbsolutePath())
at the beginning of the main method.
Many recommended to mention the library name without .dll extension, but for me it worked only with .dll. Moreover, I had to load not only the needed library but also all the libraries that my library depends on. For example: my library depends on EntityFramework.dll
, so i had to include this line in the main method:
System.load(new java.io.File("path/EntityFramework.dll").getAbsolutePath());
After exporting the project into a runnable jar file and tested from the cmd with statement java -jar exported-file.jar
, I was then able to see the outputs correctly in the console. I just posted this answer in case someone is facing such an error and searching a solution.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments