• Post Reply Bookmark Topic Watch Topic
  • New Topic

locating native files  RSS feed

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Guys,

Isn't there a way to programatically tell an application where to find native libraries? For my application I want to store all native library files into a folder named "native". Like so:



I don't want to use the -D option at the command prompt.
I've tried:

String appPath = System.getProperty("user.dir");
System.setProperty("java.library.path" , appPath + File.separator + "native");
System.load(System.getProperty("java.library.path") + File.separator + "some.dll");

but all this gets me is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\PNS_1.0\PersonalNetSearch\native\some.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
...

This is clearly not working. Is there another way? I was so hoping I didn't have to involve JNI for something as simple as this.

Please advise.

Alan
 
Saloon Keeper
Posts: 4038
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using the direct path (without involving any other properties) in the System.load call? That should work.

Or something like System.getProperty("user.dir") + File.separator + "native" + File.separator + "some.dll"?
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey...I just discovered something interesting...

When I run my application jar file from the command prompt using: java -jar myapp.jar

my code for System.load( ) doesn't trigger the UnsatisfiedLinkError. But if I try to run my app from a script file named start.bat (which has the same command as above) or within Eclipse, I get the error. Any idea as to what's going on there?

Alan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!