Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Java - dll in jar?

 
Thread Tools Search this Thread
Old 05-16-2005, 10:14 PM   #1
DeMarcus
 
Posts: n/a
Default dll in jar?


Why can't I put my dll in a jar and load it
just like I load my icons?

Daniel

  Reply With Quote
Old 05-16-2005, 10:43 PM   #2
Boudewijn Dijkstra
 
Posts: n/a
Default Re: dll in jar?

"DeMarcus" <> schreef in bericht
newsX8ie.137685$...
>
> Why can't I put my dll in a jar and load it
> just like I load my icons?


Because dll's are libraries and icons are regular resources.


  Reply With Quote
Old 05-16-2005, 10:47 PM   #3
Steve Sobol
 
Posts: n/a
Default Re: dll in jar?

Boudewijn Dijkstra wrote:
> "DeMarcus" <> schreef in bericht
> newsX8ie.137685$...
>
>>Why can't I put my dll in a jar and load it
>>just like I load my icons?

>
>
> Because dll's are libraries and icons are regular resources.


And what good would a DLL do if you aren't running your Java app on Windows...?


--
JustThe.net - Apple Valley, CA - http://JustThe.net/ - 888.480.4NET (463
Steven J. Sobol, Geek In Charge / / PGP: 0xE3AE35ED

"The wisdom of a fool won't set you free"
--New Order, "Bizarre Love Triangle"
  Reply With Quote
Old 05-17-2005, 05:30 AM   #4
castillo.bryan@gmail.com
 
Posts: n/a
Default Re: dll in jar?

I'm guessing that most JVMs uses the function LoadLibraryEx for windows
and dlopen for unix. Both of these C functions take a string which
gets mapped to a file (in most cases). Niether of these C functions
know how to load libraries out of jar or zip files.

In order for a java application to load these from a jar, they would
probably have to extract the dll's or SO's from the jar to the
filesystem. You could do this manually in your static initializer if
you really wanted to.

I believe that there is an option to specify native libraries, for use
in webstart applications, downloaded from a webserver. You might take
a look at how webstart does it, or just use webstart for deployment.

Basically, loading executable native code into a process space is
beyond the scope and control of the JVM and the JVM has to fit within
the confines of the OS.

I'm guessing that you are running into some deployment issues. You
might want to describe the environment and the problems you are having.
However, you might just be curious.......

  Reply With Quote
Old 05-17-2005, 06:35 AM   #5
Tor Iver Wilhelmsen
 
Posts: n/a
Default Re: dll in jar?

DeMarcus <> writes:

> Why can't I put my dll in a jar and load it
> just like I load my icons?


Because Windows doesn't look for DLLs in jars.
  Reply With Quote
Old 05-17-2005, 06:46 AM   #6
DeMarcus
 
Posts: n/a
Default Re: dll in jar?



Steve Sobol wrote:
> Boudewijn Dijkstra wrote:
>
>> "DeMarcus" <> schreef in bericht
>> newsX8ie.137685$...
>>
>>> Why can't I put my dll in a jar and load it
>>> just like I load my icons?

>>
>>
>>
>> Because dll's are libraries and icons are regular resources.

>
>
> And what good would a DLL do if you aren't running your Java app on
> Windows...?
>
>


You've got a point there.

  Reply With Quote
Old 05-17-2005, 06:49 AM   #7
DeMarcus
 
Posts: n/a
Default Re: dll in jar?



wrote:

> I'm guessing that most JVMs uses the function LoadLibraryEx for windows
> and dlopen for unix. Both of these C functions take a string which
> gets mapped to a file (in most cases). Niether of these C functions
> know how to load libraries out of jar or zip files.
>
> In order for a java application to load these from a jar, they would
> probably have to extract the dll's or SO's from the jar to the
> filesystem. You could do this manually in your static initializer if
> you really wanted to.
>
> I believe that there is an option to specify native libraries, for use
> in webstart applications, downloaded from a webserver. You might take
> a look at how webstart does it, or just use webstart for deployment.
>
> Basically, loading executable native code into a process space is
> beyond the scope and control of the JVM and the JVM has to fit within
> the confines of the OS.
>
> I'm guessing that you are running into some deployment issues. You
> might want to describe the environment and the problems you are having.
> However, you might just be curious.......
>


I was just curious why System.loadLibrary() can't take a URL instead
of a String, but the fact that it violates portability having a dll in
a jar may be a good explanation to me.


  Reply With Quote
Old 05-12-2006, 02:30 AM   #8
eytan
Junior Member
 
Join Date: May 2006
Posts: 1
Default There is a way to dynamically deploy dll or so from jar

Hi

This works:
  • detect the operating system - using os.name property for example
  • locate the appropriate dynamic library in the jar as a class resource
  • copythe lib content into a local file
  • load the library
e.g.:
Assuming the library reside on the class path as a resource of
ResourceLocator class.
Code:
String system = System.getProperty("os.name"); String libExtension = "Windows".equals(system) ? ".dll" : "Unix".equals(system) ? ".so" ...; String mylibName = "myLibrary" + libExtension; URL libUrl = ResourceLocator.class.getResource(mylibName); File file = new File(mylibName); if (!file.exists()) file.createNewFile(); FileReader in = new FileReader(new File(libUrl.getFile()); FileWriter out = new FileWriter(file); byte[] buffer = new byte[1048]; while(in.available() > 0) { int read = in.read(buffer); out.write(buffer, 0, read); } out.close(); System.loadLibrary("myLibrary");

Last edited by eytan : 05-12-2006 at 02:49 AM.
eytan is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47