System.load( "a.dll" ) from within .jar

F

Fabricio

Hi there,

Just wondering if anybody has managed to load a .dll library file from
within a jar file. (for a Java Native Interface JNI project)

I've tried:

System.load( "c:/dir/jarfile.jar!/package/a.dll" );

System.load( package.ClassName.class.getResource( "a.dll" ).getFile() );

But to no avail...

I don't want to copy the dll to a path that windows recognises c:\windows
or c:\winnt (and use System.loadLibrary( "a.dll" ); ).

I was hoping I could 'gracefully' encapsulate the dll in my jar file.

Thanks in advance

Fabricio
 
A

Andy Flowers

If the DLL is in the Jar files then Windows will have no way of getting to
it and loading it. It is a requirement of the WIN32 memory management/DLL
loading system that the DLL be accessible to the native file system (FAT or
NTFS).

You will have to extract it from the jar file to use it.

Perhaps you could extract it from the JAR file to the same directory as the
jar file and use it from there. This would be done on the first run as
subsequent runs will just look for the DLL being there already and will just
use it.
 
R

Roedy Green

Just wondering if anybody has managed to load a .dll library file from
within a jar file. (for a Java Native Interface JNI project)

The problem is the native OS has to load the DLL eventually. Somebody
has to extract it from the jar. I think it has to be you. The catch
is finding a suitable place to put it.
 
J

javamad

Thanks for the help Andy + Roady.

Andy, I like the idea of extracting the dll from the jar file on the first
run and doing checks for it on subsequent runs. At least it means I can
send my project as a single .jar file.

I will try it now!

Fabricio.
 
Joined
Dec 26, 2007
Messages
1
Reaction score
0
But how would you copy dll into a directory that is write protected? I need a Limited user to run my applet , and in that case , I cant copy a dll to C:\Program Files\ ... or C:\Windows\ ...
And dependecy library call's method System.loadLibrary()
I used com4j and I'm facing this problem...some sugestions??
I cant go myself and do a copy-paste for all 250 users, and log in to their machine as admin user... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top