0

I'm having a problem with loading dll placed in dll folder file inside my Java code. To make it simple - I try to execute load dll inside exampleTest.java but I get UnsatisiefLinkException.

Project structure

I tried:

InputStream in = this.getClass().getClassLoader().getResourceAsStream("../dll/file.dll");

But it doesn't work. Do anyone has any idea how to solve this issue?

Mister S
  • 203
  • 1
  • 7
  • 14
  • Why do you want to get the DLL as an input stream? What are you trying to achieve? – maba Aug 13 '12 at 09:55
  • Is it a kind of continuation of your previous question: http://stackoverflow.com/questions/11929864/java-with-jacob-how-to-properly-set-java-library-path? – maba Aug 13 '12 at 10:14
  • You are posting the exact same question again: http://stackoverflow.com/questions/11345657/dealing-with-getresourceasstream-for-outside-file – maba Aug 13 '12 at 10:23
  • because my problem wasn't solved as I thought... – Mister S Aug 13 '12 at 11:07
  • It would be nice from you to give feedback on answers given to yo and note them so that it's useful to others – UBIK LOAD PACK Aug 13 '12 at 20:49

5 Answers5

0

add dll to runtime classpath and change your code to

InputStream in = this.getClass().getClassLoader().getResourceAsStream("/dll/file.dll");
jmj
  • 237,923
  • 42
  • 401
  • 438
  • how to add dll to runtime classpath in eclipse? – Mister S Aug 13 '12 at 10:00
  • if it is web project dll should go under WEB-INF/lib, in general it should be placed next to your root class package, parallel to com (containing classes) – jmj Aug 13 '12 at 10:02
0

getResourceAsStream() considers your source folder as a root of the "filesystem". As far as I know you cannot access folder via getResourceAsStream() if this folder is outside of src folder.

If you want to access that dll file, move dll folder to src folder. And access it via

getResourceAsStream("/dll/file.dll")

Check this post. It is about another question, but the main point is the same I think.

Community
  • 1
  • 1
0

If you want to load it as a ressource, you should make your dll folder into a source folder. Rightclick on folder -> Build Path -> Use as source folder

You can then simply load it like this:

InputStream in = this.getClass().getClassLoader().getResourceAsStream("dll/file.dll");
brimborium
  • 9,362
  • 9
  • 48
  • 76
0

May be try something like this.

You don't need to include the dll but the path should be enough.

System.setProperty("java.library.path", "/dll" + File.pathSeparator +
System.getProperty("java.library.path"));

Add the above line before executing your code. This will add the dll path to the jvm runtime library.

And it also depends on the folder from where you are running your application. You need to give a relative path for the dll folder. Alternatively you can give a Fully Qualified path but then it is not recommended from project configuration point of view.

0

If you're just wanting it imported, you could always use the System loadLibrary and nio.Paths, like this:

System.loadLibrary(Paths.get("/dll/file.dll").toString());

Which is effectively a wrapper for:

Runtime.getRuntime().loadLibrary(Paths.get("/dll/file.dll").toString())
MrLore
  • 3,759
  • 2
  • 28
  • 36