can a java app link and load an straight win32 dll?

Hi ,

sorry if these question has been asked before. I've been looking but havent found a link that answers my questions.

Can i make my java app link and load 3rd party Win32 dlls & libs? I do not have access to their source code, so i cannot 'java'fy them in any way.

I'd like to have the app and libraries eventually run on the Mac too. Any tips on what is the best way to do a Java for Mac app?

Links will be much appreciated.

Thanks

[490 byte] By [3libras] at [2007-9-26 3:18:48]
# 1

yes,

my dear u can load win32 dll with System.loadLibrary(dll name) or Runtime.LoadLibrary(dll name).

another way to load the dll in the your native implemented dll and call in your java code as using JNI. this is the way which i preffered and using in my own application.

Best Regards,

Imran Mustafa

imranmustafa at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 2

As already noted, you can load your libraries with System.loadLibrary(libname);

The best way to do this is to specifiy a static section in your class.

class foo {

static {

try {

System.loadLibrary(libname);

}catch(UnsatisfiedLinkError e){

e.printStackTrace();

}

}

}

Note that the libname is specified without the .dll.

e.g you have Win32.dll just type Win32.

UNIX: you have libMyTools.so type MyTools

The library has to be in the PATH-Enviroment Variable or under UNIX in the LD_LIBRARY_PATH or LIBPATH (depends on the platform).

Now you know how to link a library, but you have to access the methods in the native third-party-libraries.

Therefor you need to write your own library (and load it in java) that is called via JNI from java and will call the native third-party methods.

This is independent of the platform you are using.

For JNI see : http://java.sun.com/docs/books/tutorial/native1.1/index.html

kuss at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 3
Take a look at Coroutine for Java at http://www.nevaobject.com/java/index.htm. It allows you to load various DLL's and invoke arbitrary functions without having to go through the effort to write JNI stuff.As for the Mac, I haven't a clue.Chuck
cmccorvey at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 4

I would recomend writeing a C/C++ wrapper so you can

easily cope with changes to the DLL, the wrapper should

1: be easily coupled with th JVM.

2: folow the same syntax for windows & mac.

3: load & execute what you want from the dll.

this allows flexability, and makes the process of integration easier.

Its a bit more work, but you will thank you're self down the road.

musheno at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 5

If you will require a native library you will need to load that lib on ALL systems it will run on, and as you said you cannot modify, unless you get a mac version of your libraries, you are out of luck (but you would of been out of luck even with assmebly, since you are not willing to port the lib).

Sorry :-(

Todd_Muhsheno@yahoo.com

musheno at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 6

From Your Mail I tried and got somewhat but still UnsatisfiedLinkerError came for me in Java for my Usage of My own Application.

My Program is to set the classpath Permanantly using Java Program,. If anybody have that Coding Means Please Mail To the Address of

ragava.it@gmail.com or ragava_07it@yahoo.co.in

Ragava at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...
# 7

The issue is that you do not have the native code on the system that you are trying to run on.

Your options are...

Get the Libraries for that OS from the vendor of the other system

Write the Libraries for that OS

Create a Java based library to fall back on in the case the native library is not found

I recommend the last one as you will then have a cross platform app.

Todd

musheno at 2007-6-29 11:33:14 > top of Java-index,Developer Tools,Java Compiler...