loading dll within a jar

P

Philipp Kraus

Hello,

is there a way to load a DLL library that is stored within a Jar?
At the time I'm using the -Djava.library.path flag but I would like
to store the DLL within the Jar and added the path dynamically.

I've found some information about this eg extract the DLL to the
temp directory and set the -D option on the main-method.

Can I set also the library path to the java command like the classpath
argument? My java classes use the a
static { System.loadLibrary("dllname"); }
to load the library, so can I add on the static attribute a call for loading
the dll within the jar?

Thanks

Phil
 
O

Owen Jacobson

Hello,

is there a way to load a DLL library that is stored within a Jar?
At the time I'm using the -Djava.library.path flag but I would like
to store the DLL within the Jar and added the path dynamically.

I've found some information about this eg extract the DLL to the
temp directory and set the -D option on the main-method.

Can I set also the library path to the java command like the classpath
argument? My java classes use the a
static { System.loadLibrary("dllname"); }
to load the library, so can I add on the static attribute a call for loading
the dll within the jar?

Thanks

Phil

DLL files (and their Unix counterparts) are loaded by the OS's binary
image loader, which near-universally expects a program or library to
come from a file on the filesystem. A loader that's clever enough to
look inside a ZIP file is a rare beast indeed.

Short answer, no, you can't get there from here. Unpack your .DLL
somewhere (java.io.tmpdir, for example) and load it from there. The
Java Web Start protocol includes support for native libraries
distributed inside JAR files, if you don't want to write the
unpack-and-load glue yourself and if your app is appropriate for web
start.

-o
 
R

Roedy Green

is there a way to load a DLL library that is stored within a Jar?

The easiest way is to use Java Web Start. It will even select the
dll/object code for the particular platform.
see http://mindprod.com/jgloss/javawebstart.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
P

Philipp Kraus

DLL files (and their Unix counterparts) are loaded by the OS's binary
image loader, which near-universally expects a program or library to
come from a file on the filesystem. A loader that's clever enough to
look inside a ZIP file is a rare beast indeed.

Short answer, no, you can't get there from here. Unpack your .DLL
somewhere (java.io.tmpdir, for example) and load it from there. The
Java Web Start protocol includes support for native libraries
distributed inside JAR files, if you don't want to write the
unpack-and-load glue yourself and if your app is appropriate for web
start.


Thanks for your answers. I will take a look to the Webstart but I think
I write my own glue code

Phil
 
R

Roedy Green

Short answer, no, you can't get there from here. Unpack your .DLL
somewhere (java.io.tmpdir, for example) and load it from there. The
Java Web Start protocol includes support for native libraries
distributed inside JAR files, if you don't want to write the
unpack-and-load glue yourself and if your app is appropriate for web
start.

Doing this with applets is a bear. A long time ago I went nearly nuts
trying to do it under Netscape and brethren and Java 1.1. The problem
was Java did not notice the DLL unless it were present when Java was
first loaded. You have to find a place to put the DLL on the library
path. You need permission to put it there.

It is easier to let Java Web Start handle this for you. If you use an
installer, it should have facilities to install the DLL for you. See
http://mindprod.com/jgloss/installer.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
P

Philipp Kraus

Doing this with applets is a bear.

No it will be a standalone package.
A long time ago I went nearly nuts
trying to do it under Netscape and brethren and Java 1.1. The problem
was Java did not notice the DLL unless it were present when Java was
first loaded. You have to find a place to put the DLL on the library
path. You need permission to put it there.

It is easier to let Java Web Start handle this for you. If you use an
installer, it should have facilities to install the DLL for you. See
http://mindprod.com/jgloss/installer.html

At the moment I use a swtich to load the library, the load will be first
from the default system lib path or the user can specify the path

Grat hint, thank

Phil
 
R

Roedy Green

is there a way to load a DLL library that is stored within a Jar?

see http://mindprod.com/jgloss/javawebstart.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
A

Arne Vajhøj

is there a way to load a DLL library that is stored within a Jar?
At the time I'm using the -Djava.library.path flag but I would like
to store the DLL within the Jar and added the path dynamically.

I've found some information about this eg extract the DLL to the
temp directory and set the -D option on the main-method.

Can I set also the library path to the java command like the classpath
argument? My java classes use the a
static { System.loadLibrary("dllname"); }
to load the library, so can I add on the static attribute a call for
loading
the dll within the jar?

The right answer is having the DLL external.

Use JWS for SE and JCA for EE to get a little help.

If you really want to mess around then you embed
JLAN in your app, have it serve the jar file as
a windows share and load from that share.

I would not do that.

Arne

PS: JLAN is either GPL or commercial license with the
implications that carry.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top