jni

calling a c++ function from java which uses some other function which refers include files

Hi all, i am trying to call a navite method defined in c++ from java, the function which i am trying to call refers some functions defined in header files and also the other functions defined by me... is it passible to call that?.. i am getting an error "error LNK2019-unresolved external symbol".. can any one help me to do this... ...

JNI Stream binary data from C++ to Java

I need help passing binary data into Java. I'm trying to use jbytearray but when the data gets into Java it appears corrupt. Can somebody give me a hand? Here's a snip of some example code. First the native C++ side: printf("Building audio array copy\n"); jbyteArray rawAudioCopy = env->NewByteArray(10); jbyte toCopy[10]; printf("Fillin...

JNI AttachCurrentThread NULLs the jenv

Hello all, I'm currently in the process of adding JNI functionality into a legacy delphi app. In a single-threaded environment everything works fine, but as soon as I move into multi-threaded environment, things start to become hairy. My problem is that calling JavaVM^.AttachCurrentThread( JavaVM, @JEnv, nil ); returns 0, but puts the ...

odd problem with jni interacting with dll's - not sure why a change to gc ergonomics fixes it

We were having a problem with our Tomcat jvm blowing up and giving us an hs_* dump at random times but always in the same spot, that wasn't very informative other than saying we had an EXCEPTION_ACCESS_VIOLATION Commenting out various parts of the java that called particular jni functions just made it blow consistently in another spot. ...

New to C/C++ Using Android NDK to port Legacy code, getting compile errors

I have been trying to take some old Symbian C++ code over to Android today using the NDK. I have little to no C or C++ knowledge so its been a chore, however has to be done. My main issue is that I'm having trouble porting what I believe is Symbian specifi code to work using the small C/C++ subset that is available with the Android NDK...

JNI - native method with ByteBuffer parameter

I've got a method: public native void doSomething(ByteBuffer in, ByteBuffer out); Generated by javah C/C++ header of this method is: JNIEXPORT void JNICALL Java__MyClass_doSomething (JNIEnv *, jobject, jobject, jobject, jint, jint); How can I get a data array from jobject (that is a ByteBuffer instance) ? ...

How can I include platform-specific native libraries in the .JAR file using Eclipse?

Hello all, I am just starting to learn JNI. I have been following a simple example, and I have created a Java app that calls a Hello World method in a native library. I'd like to target Win32 and Linux x86. My library resides in a DLL, and I can call it just fine using LoadLibrary when the DLL is added to the root of my Eclipse proje...

How to restart the Java Process with -Djava.library.path?

Hi guys, I have an application that is started with JWS. The first time user launches this application he has to choose a path where Berkeley DB XML is installed. I do need this to set the native library path and restart the application with -Djava.library.path parameter. Berkeley DB XML java bindings uses JNI to make calls to the datab...

DLL takes forever to load in JNI class

Hi, I'm working with a jni application that loads a dll library, but the load of it is taking too long. The dll is in the path. As a relevant informat, this dll depends on other oracle dlls that are also in the path. System.loadLibrary("exmaple.dll"); Do you have any idea why the load never ends? ...

Safe to pass objects to C functions when working in JNI Invocation API?

I am coding up something using the JNI Invocation API. A C program starts up a JVM and makes calls into it. The JNIenv pointer is global to the C file. I have numerous C functions which need to perform the same operation on a given class of jobject. So I wrote helper functions which take a jobject and process it, returning the needed...

How can I make Swig correctly wrap a char* buffer that is modified in C as a Java Something-or-other?

I am trying to wrap some legacy code for use in Java and I was quite happy to see that Swig was able to handle the header file and it generate a great wrapper that almost works. Now I am looking for the deep magic that will make it really work. In C I have a function that looks like this DLL_IMPORT int DustyVoodoo(char *buff, int len...

jstring to L_TCHAR* format

Hi All, I have been trying to call a C function that has the following signature int changeFoo(L_TCHAR* pszFileSrc){....} in my JNI call my method looks like this: JNIEXPORT jint JNICALL Java_com_me_L_AFoo(JNIEnv * env, jclass jclass, jstring pSrc) { jint retValue = -100; retValue = changeFoo(pSrc); return retValue; } I...

Jarring/flattening out a lib directory using jarjar and ant

I'm trying to flatten out the lib directory of a project using jarjar, where it will produce a jar file with my main code and all my required libraries inside of it. I can get the project code into the jar, but I need to find a way to get every jar in the './lib/' directory extracted to the base directory of the final output jar. I don...

How to Use Eclipse to Debug JNI code (Java & C/C++)

While I can debug my application with the Eclipse JDT debugger for Java code and GDB for C code, I would prefer to use a single tool for all my debugging. I found several projects that enable "mixed-mode" debugging in Eclipse and include support for single stepping between Java and native code. Intel's Integrated Debugger for Java/JNI...

Why is glpk-java.jar not the same across all platforms?

I'm using glpk-java in one of my projects. It provides a JNI to GLPK, a free LP/MIP solver. To use it under different platforms, you need different shared libraries (libglpk.so under Linux, libglpk.dylib under Mac OS X, glpk.dll under Windows) which is fully understandable. In addition, a java library is needed: glpk-java.jar. It's creat...

Creating java executable using JNI ?

I am trying to create executable under windows platform for Java program using JNI ,C/C++ and invocation API, I have already created jar file for my program which includes all dependencies. I want to embed it in exe file, I was successful in running simple main class(present in file system) using JNI invocation API, I am planning to ad...

Does MemoryMXBean report JNI memory usage?

Do the heap usage results returned by MemoryMXBean include any memory allocated by JNI libraries used by the application? Any experience? The documentation does not make this clear. ...

Simple typemap example in swig java

I am trying to wrap a native C++ library using swig, and I am stuck at trying to convert time_t in C, to long in Java. I have successfully used swig with python, but so far I am unable to get the above typemap to work in Java. In python it looks like this %typemap(in) time_t { if (PyLong_Check($input)) $1 = (time_t) PyLong_...

How to load jni from sd card on android 2.1?

I want to load third-party jni library in runtime. I've tried to load directly from sdcard. It expectedly failed. I've tried to copy library from sdcard to /data/data/app/ and then System.load(/data/data/app/libjni.so) It works on HTC HERO, but fails on HTC Legend with Android 2.1. it fails during execution of native code and write to lo...

Access static enum fields using JNI invocation API

How can we access static enum fields using JNI invocation API I am trying to access glassfish org.glassfish.api.embedded.ContainerBuilder.Type enumeration from Glassfish api using following code jclass Type= env->FindClass( "org/glassfish/api/embedded/ContainerBuilder$Type"); jfieldID Type_web=env->GetStaticFieldID( Type,"web"...