Question

I've inherited a legacy J++ project. I've upgraded this project to standard Sun Java successfully.

However, this project includes a native C++ dll which the Java code talks to via the Microsoft-specific RNI framework.

Needless to say, calling System.loadLibrary("myRniNativeDll") now throws a UnsatisifiedLinkError, saying one of the dependencies couldn't be found.

I'm totally clueless how to migrate a C++ RNI dll to a JNI dll; I've no idea where to begin. I have the C++ source code, but I don't know how to build a JNI dll. Are there any tips/tutorials/online materials you Java experts can point me to?

Was it helpful?

Solution

If the licensing is acceptable (LGPL), Java Native Access provides a rather friendlier FFI than the JNI does; porting may reduce to stripping away the RNI layer and just exposing a simple 'C'-callable API.

OTHER TIPS

Take a look at JNA - it might be possible to access the RNI DLL directly that way; or at least it will make the job of porting it much easier than doing JNI manually.

If possible, I suggest that you consider avoiding the RNI -> JNI porting problem by rewriting the C++ code in pure Java.

Writing JNI code requires a huge amount of care, and places JVM stability at risk if you get it wrong. My advice is to avoid it if you possibly can.

While I have never used Microsoft's RNI, only Sun's JNI, I would expect that you couldn't directly use an RNI-style DLL as if it were a JNI-style DLL. I am also unaware of anything that would automatically convert or bridge RNI to JNI.

You do not mention if you have the source to the C++ RNI DLL, although I'll assume you do since you mention inheriting the project. If you have any C++/C experience, and have a good idea of what functionality the RNI DLL is providing, it should not be too difficult to move it to JNI. The time invested in porting it would likely pay off for maintaining it moving forward.

The link you provided to the JNI entry on Wikipedia has lots of helpful links on coding with JNI. Without a bit more detail, it is hard to give any other advice.

Java Native Interface: Programmer's Guide and Specification is the best resource that I've found for writing JNI code. It doesn't cover RNI -> JNI, but it is a great* starting point for learning how JNI works.

*It's actually very dry, and not particularly fun to read, but it's the best I've been able to find.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top