Extracting DLL from JAR for use in JNI

From: Mark Osborn (ozziepeepsNOSPAM_at_yahoo.co.uk)
Date: 03/31/04


Date: 31 Mar 2004 03:35:56 -0800

Dear All,

I'm having trouble extracting a DLL file from a JAR file. The code I
give below used to work, but for some reason its broken now!

I've written an application that uses "plugins" shipped as JAR files.
When my main application instanciates a JAR file, it checks to see if
any native DLL's need to be extracted from the JAR to the plugin
folder, such that JNI calls can be made upon the DLL.

The code I have is as follows:

InputStream inputStream =
LeadToolsOCRPlugIn.class.getResourceAsStream("/mydll.dll");
FileOutputStream outputStream = new FileOutputStream(temporaryDll);
byte[] array = new byte[8192];
for (int i = inputStream.read(array); i != -1; i =
inputStream.read(array))
   outputStream.write(array, 0, i);

outputStream.close();

The first line fails with NullPointerException - i.e. it cant find the
DLL inside the JAR, yet inspection of the JAR shows the DLL in the
root of the JAR file, and I've rebuilt the JAR many times in JBuilder
and all appears to be fine.

Any suggestions would be much appreciated! Either reply to the group,
or to my e-mail, removing the bit in CAPITALS.

Cheers,

Mark



Relevant Pages

  • System.loadLibrary problem
    ... I've created a dll called Win32Registry.dll ... Win32RegKey in package win32regkey. ... when I take the same dll and jar file and drop them into a lib ... Everything works fine with jst. ...
    (comp.lang.java.programmer)
  • Re: using reflection to load a jar file and its dll
    ... Barry wrote: ... > aforementioned dll. ... if I add the jar file to the ... that your "custom" classloader has the JVM bootstrap classloader as a ...
    (comp.lang.java)
  • using reflection to load a jar file and its dll
    ... My application requires a jar file be loaded dynamically at runtime, ... aforementioned dll. ... aforementioned exception is not thrown? ...
    (comp.lang.java)
  • class loader getResourceAsStream
    ... I'm trying to get a resource who is stored into a jar file. ... following path to the resource from the root of the jar ... InputStream inputStream = ...
    (comp.lang.java.programmer)