java-native-interface

Calling Java functions from C language

[亡魂溺海] 提交于 2020-01-04 04:05:09
问题 I am tying to call java functions from c code. I used the JNI as discussed in the example at http://www.ishaanguliani.com/content/calling-java-functions-c-linux-ubuntu-jni I used the same code and followed the same steps but I am getting unable to find the class print. I debugged but I didnt find what I did wrong. Sharing my code here unions@universe:~/uni_tmp/jni/vvn$ cat MyC.c #include <stdio.h> #include <jni.h> #include "MyJava.h" #include <string.h> JNIEnv* create_vm(JavaVM ** jvm) {

Is there a way to prevent Tomcat from crashing when a loaded JNI library corrupts memory?

不羁岁月 提交于 2020-01-04 02:48:08
问题 We have a web application running on Tomcat 7 and it loads a JNI library module that was coded in C++ and which was developped by a third party. Basically, this library provides biometric technology to our web app. We cannot use an all java solution for this and have no other choice than to use that JNI library module. The problem is that sometimes, the JNI library module crashes because it does a segmentation fault and corrupts memory. When that happens, it makes Tomcat crash completely

If my code uses RTTI then it will not work on android?

安稳与你 提交于 2020-01-04 02:45:09
问题 I read in Android Native Development Kit Cookbook that: By default, Android provides minimal C++ support. There's no Run-time Type Information (RTTI) and C++ exceptions support, and even the C++ standard library support, is partial. The following is a list of the C++ headers supported by Android NDK by default: cassert, cctype,cerrno, cfloat, climits, cmath, csetjmp, csignal, cstddef, cstdint, cstdio, cstdlib, cstring, ctime, cwchar, new, stl_pair.h, typeinfo, utility It is possible to add

Should I call PushLocalFrame and PopLocalFrame when I call Java Method From C++?

懵懂的女人 提交于 2020-01-04 02:32:10
问题 Question 1: I have a java class with a static method: class Test { static public void show (String value) { // dosomething with value } } If I want call it from c++: jstring value = env->NewStringUTF("Hello, World"); // ExceptionCheck after NewStringUTF. env->CallStaticVoidMethod(the_jclass, the_jmethodID, value); // ExceptionCheck after CallStaticVoidMethod. Should I put PushLocalFrame before NewStringUTF and put PopLocalFrame after CallStaticVoidMethod to release local references? Question

JNI for C using Swig & trouble with function pointer callback

放肆的年华 提交于 2020-01-04 01:49:21
问题 we have a C function in one of the libraries which are loaded in java, which accepts a function pointer function defination as below typedef char int8 typedef unsigned short uint16 uint32 poll_broadcasts(void *(pfn)(int8*,uint16)); In C it is used as below void handle_broadcasts( int8 *broadcast, uint16 length ) uint32 a = poll_broadcasts( (void*(*)(int8*,uint16)) handle_broadcasts ) But when you use Swig to generate JNI wrapper it creates following definition for poll_broadcast public static

JAVA JNI C Debugger

久未见 提交于 2020-01-04 01:23:11
问题 Is there any debugger that helps debug a Java JNI program along with the C library? I should be able to debug the program starting from static void main in Java and continue to debug and place break points in the native c function and then continue to debug in Java after the control is transferred from C to Java. 回答1: A Java Virtual Machine debugger is very different from native code debugger. There is currently no such MATURE solution as one and the same debugger which would be able to

Nar dependency in multi-module maven project

给你一囗甜甜゛ 提交于 2020-01-03 18:55:33
问题 I set up a multi module maven project, which is comprised of a module destined to build nar jni library, and a jar packaged module that is dependent on that library. I am able to install the nar library to my local maven repository, but I fail to use it in dependent module. For instance, I run mvn nar:nar-unpack and I get: [INFO] ------------------------------------------------------------------------ [INFO] Building nar-dependent 1.0-SNAPSHOT [INFO] ------------------------------------------

JNI - Listener in C++/Java - is it possible to instantiate Java objects in c++ and use them as parameters

£可爱£侵袭症+ 提交于 2020-01-03 17:44:25
问题 Is the following usable with JNI? public NativeClass { static { System.loadLibrary("dll"); } public static native void addListener(Listener listener); } public interface Listener { public void eventOccurred(Info info); } public Info { private final String s1; private final String s2; public Info(String s1, String s2); // ... getters for use in Java } Is it possible to register a Listener object on a dll (should be no problem, as far as I found out) instantiate an Info object in the c/c++ code

JNI - Listener in C++/Java - is it possible to instantiate Java objects in c++ and use them as parameters

拈花ヽ惹草 提交于 2020-01-03 17:44:14
问题 Is the following usable with JNI? public NativeClass { static { System.loadLibrary("dll"); } public static native void addListener(Listener listener); } public interface Listener { public void eventOccurred(Info info); } public Info { private final String s1; private final String s2; public Info(String s1, String s2); // ... getters for use in Java } Is it possible to register a Listener object on a dll (should be no problem, as far as I found out) instantiate an Info object in the c/c++ code

UnsatisfiedLinkError: Native method not found - Android

余生颓废 提交于 2020-01-03 17:05:41
问题 I am developing an android app using C++ code. Trying to use JNI but failed. The code in myFirstApp.cpp JNIEXPORT jint JNICALL Java_com_example_myfirstapp_CreateApp_findMarkersNative( JNIEnv* env, jobject, jlong addrRgba) { //clock_t begin = clock(); Mat& mRgb = *(Mat*) addrRgba; Mat mgray(mRgb.rows, mRgb.cols, CV_8UC1); cvtColor(mRgb, mgray, CV_RGBA2GRAY, 1); // the working one clearVectors(); findSquares(mgray); mergeRectangles(); processFilteredSquares(mgray);