Como Chamar C++ de Java

1. Crie a aplicação C++:

#include <iostream>

#include <jni.h>

using namespace std;

extern "C" {

  JNIEXPORT void JNICALL Java_JNISample_main(JNIEnv* env, jobject obj, jobjectArray args) {

    for (jsize sz = 0; sz GetArrayLength(args); sz++) {
      const jstring str = (jstring)env->GetObjectArrayElement(args, sz);

      const char* chars = env->GetStringUTFChars(str, JNI_FALSE);

      cout << env->ReleaseStringUTFChars(str, chars);



2. Gere a DLL.

3. Crie a aplicação Java:

public final class JNISample {
  public static native void main(final String[] args);

4. Execute a aplicação Java:

java JNISample Simples Assim

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s