jni

Is there a way to call the STL Libraries of C++ from Java using JNI?

Is there a way to call STL libraries from JNI, I believe JNI provides a C like interface for native calls, how do we achieve this for the C++ template libraries? ...

JNI vs Runtime.exec()

I have two options - I can either use JNI or use Runtime.exec to execute a C++ library. The C++ program is CPU intensive and long running i.e. some calls may take up to a couple of hours to return. What are the pros and cons of each? Which approach should I go for? ...

Do you know of any JNI wrapper toolkits or libraries that wrap common linux OS APIs?

I'm looking for a library or toolkit (so I don't have to write it) that will allow me to do common things like the following in Linux: Get the uid for a username. Get user / group membership information. Get information about free space on disk drives. Any other potentially useful API calls that are not normally available in Java becau...

Java: How are errors customarily handled for native code in jni calls?

I've google'd around a bit, and haven't really found a good answer for my question: What is the customary way to pass back error information to java from native jni code? I would normally just pick a design and go with it, but this code is called every 5 milliseconds, (approx), so I thought I'd ask if there's a customary 'clean / effic...

JNI vs. C++ Object Instances

I have just started at a new job. Here we are new to using JNI ( for bridging C++ / Java ). I am new to JNI so please forgive my noobness :) In our (win32) Java app we are loading a C++ DLL. On the Java side we have several instances of "SomeJClass" each of these instances needs access to corresponding instance of "SomeCClass" on the DL...

How do I get an error message when failing to load a JVM via JNI?

I would like to retrieve an error message that explains why the jvm failed to load. From the examples provided here: http://java.sun.com/docs/books/jni/html/invoke.html I extracted this example: /* Create the Java VM */ res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); if (res < 0) { // retrieve verbose error here? f...

Event listener in Java without app having focus? (Global keypress detection)

I've been searching for a while and everybody seems to think this is not possible using just Java, so I'll give SO a shot ;) Is there any way to have my Java application listen for events (key events in particular) while another unrelated application has window focus? In my situation, I'm looking to detect when the user has pressed the ...

Do I need to clean up the char* passed to NewStringUTF?

I think yes, but the top 12 examples I found all do something not illustrative like JNIEXPORT jstring JCALL Java_com_foo_dumbImpl(JNIEnv* env, jobject thisObj) { return (*env)->NewStringUTF(env, "constant string"); } so for posterity I will ask: this is bad, yes? JNIEXPORT jstring JCALL Java_com_foo_dumbImpl(JNIEnv* env, jobject t...

Load a PNG image into Java as BufferedImage through JNI C code

Hi, I have the following problem. I have C code that acquires a PNG image as basically raw data and keeps it in memory. I would like this raw data to be translated to a BufferedImage in Java, through the use of JNI. Does anyone know any way of doing this or has done this before? ...

Use windows static libraries from java code with minimal effort (prefereably using JNA)

I have to use some static windows library (*.lib) from java code, I can write C++ JNI wrappers, but I'd rather not do it (not that experienced in C++). What would be the easiest (least developement effort) way use it, performance is not important, since that code will just be fetching some data, that most probrably will be worked on on...

Using maven to build/deploy/use projects with JNI.

I am trying to use maven to build a project that depends on a JNI wrapper around the OpenCV computer vision library. I've been able to "maven-ize" the OpenCV wrapper here: http://ubaa.net/shared/processing/opencv/ by using FreeHEP's NAR maven plugin, but the documentation for that plugin is somewhat lacking. I've been able to create ...

Passing double-byte (WCHAR) strings from C++ to Java via JNI.

I have a Java application that uses a C++ DLL via JNI. A few of the DLL's methods take string arguments, and some of them return objects that contain strings as well. Currently the DLL does not support Unicode, so the string handling is rather easy: Java calls String.getBytes() and passes the resulting array to the DLL, which simply ...

Trying to read raw image data into Java through JNI.

I'm using JNI to obtain raw image data in the following format: The image data is returned in the format of a DATA32 (32 bits) per pixel in a linear array ordered from the top left of the image to the bottom right going from left to right each line. Each pixel has the upper 8 bits as the alpha channel and the lower 8 bits are the blue ...

Basic JNI Question : java.lang.UnsatisfiedLinkError

Hey all, JNI on Ubuntu 8.10 using Eclipse and gcc (Standard with Ubuntu if there are flavours) i can't seem to load my library despite the make file creating it succesfully. The main java class is as follows; class Hello { public native void sayHello(); static { System.loadLibrary("hello.so"); } public static...

How to debug JNI/C library?

Hi, We have system here that uses Java JNI to call a function in a C library. Everything running on Solaris. I have a problem somewhere with string encoding. An arabic character is returned by the function written in C, but the JNI methods receives a string with another encoding. I already tried setting $NLS_LANG, and the vm parameter ...

UnsatisfiedLinkError in lotus-notes plugin

Hi, We are having an issue with a dll in a notes plugin. When we call this: NotesFactory.createSession(); we get this error: Unable to create view: nlsxbe (The filename or extension is too long. java.lang.UnsatisfiedLinkError: nlsxbe (The filename or extension is too long. ) at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.j...

Memory leak using JNI to retrieve String's value from Java code

i'm using GetStringUTFChars to retrieve a string's value from the java code using JNI and releasing the string using ReleaseStringUTFChars. When the code is run on JRE 1.4 then there is no memory leak but if the same code is run with a JRE 1.5 and higher version then the memory increases. This is a part of the code: msg_id=(*env)->GetS...

Calling built-in java native methods

Is it possible to call the JVM's built-in native code, i.e. the code that various class in java.lang and java.io call? In other words, can you bypass the built-in java API to access various system-level calls such as file-system access? I know I could do this by building my own native code library and calling that via JNI, but it would b...

Java Native Interface with any arbitrary C code

I have a .dll that was provided, and I need to interface with it using java. Do I have to rewrite the C to use the JNI types provided in jni.h? as seen in java sun's jni example. Otherwise, How do i declare the native function my java function to pass and receive pointers? thanks ...

OpenSolaris Brandz and JNI a good mix?

I'd like to run a java application on a OpenSolaris machine but this application uses a dll/so that I only have the linux binary. Can it be possible, and this is because I know nothing about the OpenSolaris Brandz feature, that I can deploy the dll on a linux brandz and link to it from a jvm running on the OpenSolaris side? ...