Files
spring-soap/java-native/src/main/cpp/com_baeldung_jni_RegisterNativesHelloWorldJNI.cpp
Maciej Główka 4b62cbfac7 BAEL-4234: example of JNI registerNatives() method (#11745)
* BAEL-4234: example of JNI registerNatives() method

* fixed formatting in the cpp file

* removed camelcase in test package name
2022-02-19 09:49:07 +05:30

22 lines
682 B
C++

#include "com_baeldung_jni_RegisterNativesHelloWorldJNI.h"
#include <iostream>
JNIEXPORT jstring JNICALL hello (JNIEnv* env, jobject thisObject) {
std::string hello = "Hello from registered native C++ !!";
std::cout << hello << std::endl;
return env->NewStringUTF(hello.c_str());
}
static JNINativeMethod methods[] = {
{"sayHello", "()Ljava/lang/String;", (void*) &hello },
};
JNIEXPORT void JNICALL Java_com_baeldung_jni_RegisterNativesHelloWorldJNI_register (JNIEnv* env, jobject thsObject) {
jclass clazz = env->FindClass("com/baeldung/jni/RegisterNativesHelloWorldJNI");
(env)->RegisterNatives(clazz, methods, sizeof(methods)/sizeof(methods[0]));
}