aspose file tools*
The moose likes JNLP and Web Start and the fly likes JAR inclues native code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "JAR inclues native code " Watch "JAR inclues native code " New topic
Author

JAR inclues native code

Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
Hi

I have a small app that uses a Windows native .dll file that is packaged along with my .class files. If I package up my a app as an executable jar and execute it with "java -jar myApp.jar" everything works and the .dll file is found and loaded. If I sign the jar and create a .jnlp file for the jar, and run it as "javaws myApp.jnlp" then my program doesn't find/load the native .dll file.

Is there something else that I need to do, entries I need in my JNLP file that will make the web start process see the .dll file, or is this a restriction on Java Web Start?

Regards
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4387
    
    8

I've not tried it, but it appears you can do this by including a <nativelib> element in the JNLP file.

See these entries in the Web Start FAQ and Developer's Guide.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41835
    
  63
Yes, a nativelib element is required. In addition, both the jar file containing the native library and the jar file with the application code need to be signed.

The https://applet-launcher.dev.java.net/ class has been created precisely for this purpose.


Ping & DNS - my free Android networking tools app
Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
Matthew Brown wrote:I've not tried it, but it appears you can do this by including a <nativelib> element in the JNLP file.


Tried that. The relevant part of my jnlp is

I've used the same name as the .dll file is stored/packaged with my class files. My application code does not include directly System.loadLibary() as my app is not directly responsible for loading it. My app, mong other things uses the javax.comm package to read/write data from the serial port and it is these classes that need the dll. As I said earlier, creating a standard executable jar works just fine, the dll is found and loaded, but when I sign the executable jar and load it via web-start the dll isn't loaded.

I've tried adding System.loadLibary("win32comm.dll") and that fails because the system fails to find the dll in the java.library.path - which is true since java.library.path is a set to directories on the hard drives of the client-pc and I do not want to have to install the dll to their hard drives, I want JNLP to load it from my jar file as it does for a normal executable jar.

Sorry if I'm being a bit vague or dense but this is my first foray into Java Web Start.


Regards
Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
I've managed to get the Java console enabled and set the trace level to 5. This is what I'm getting as my application trys to launch;


The message "Properties file exists" is issued by my application imediately before I try



I've looked in in the c:\JNLP_cache\.... directory and the win32com.dll file is there. So JNLP is downloading the dll, stashing it away. The second lookup is caused when the com\sun\comm\Win32Driver.class has another tilt at loading it.

Any suggestions gratefully received.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

My suggestion would be to not use that DLL. Even when it hadn't been de-supported by Sun (which I believe happened somewhere around 2002) it was a pain to get it configured correctly. Try using the RXTX version instead.
Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
Paul Clapham wrote:My suggestion would be to not use that DLL. Even when it hadn't been de-supported by Sun (which I believe happened somewhere around 2002) it was a pain to get it configured correctly. Try using the RXTX version instead.


Without wishing to wander too far off topic, we started with the RXTX version, but reverted to the Sun version when we ran into "undocumented" features of RxTx. It may be worth re-visiting. However coming back to my original point, if I bundle everything, including win32com.dll into an executable jar and download it manually - everything works as it should - the dll is found on the classpath. It's just through JWS that it doesn't find it.

Is it a classloader issue? What is different (if anything) about the way Java Web Start fires up an app and java -jar myWebapp?

Regards
Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
Paul Clapham wrote:My suggestion would be to not use that DLL. Even when it hadn't been de-supported by Sun (which I believe happened somewhere around 2002) it was a pain to get it configured correctly. Try using the RXTX version instead.


Well roger me sensless with a ripe pineapple. Changing to the RXTX version solved the java web start loading issue. Back to the unit tests to workout why we rejected RXTX in the first place.

Thanks a million.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAR inclues native code