Вызов JNI из C ++, FindClass и импорт

0

Я получаю доступ к классу Java из C++ с использованием JNI, но FindClass всегда возвращает nil всякий раз, когда я вызываю определенный метод в своем java файле (см. Java-код). Когда я удаляю вызов, он работает нормально.

./testjnisamplecode

РЕЗУЛЬТАТ: С graph = new OrientGraphNoTx(odb); в java-коде...

No !

РЕЗУЛЬТАТ: Без graph = new OrientGraphNoTx(odb); в java-коде...

Yes !

Initializing graph .. 

Java, используя командную строку, отлично работает:

java -cp "/mypath/orientdb/debug/orientdb-c/lib/*:." Inserter

РЕЗУЛЬТАТ:

Initializing graph .. 
Initialized ok ..

C++

#include <string.h>
#include <stdio.h>
#include <jni.h>

void main()
{

  JavaVM *vm;
  JNIEnv *env;
  JavaVMInitArgs vm_args;

  JavaVMOption opts[2];
  opts[0].optionString = "-Djava.class.path=/mypath/orientdb/debug/orientdb-c:/mypath/orientdb/debug/orientdb-c/lib:/mypath/orientdb/debug/orientdb-c/lib/blueprints-core-2.5.0-SNAPSHOT.jar:/mypath/orientdb/debug/orientdb-c/lib/blueprints-orient-graph-2.5.0-SNAPSHOT.jar:.";
  opts[1].optionString = "-verbose:jni";   

  vm_args.version = JNI_VERSION_1_2;
  vm_args.nOptions = 0;
  vm_args.ignoreUnrecognized = 1;

  jmethodID mid;
  jint square;

  // Construct a VM
  jint res = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);

  // First get the class that contains the method you need to call
  jclass clazz = (*env)->FindClass(env, "Inserter");

  // TEST IF CLASS WAS FOUND
  if (clazz) {
    printf("Yes !\n");
  }
  else {
    printf("No !\n");
    exit(1);
  }

  // get init method
  jmethodID init = (*env)->GetMethodID(env, clazz, "<init>",
                                 "()V");

}

Ява

import java.io.IOException;

import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.orientechnologies.orient.core.db.graph.OGraphDatabase;
import com.tinkerpop.blueprints.TransactionalGraph;
//import com.tinkerpop.blueprints.impls.orient.OrientGraph;

import java.util.List;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.metadata.schema.OType;

public class Inserter
{
    private OGraphDatabase odb;
    private OrientGraphNoTx graph;

    public Inserter() 
    {
        System.out.println("Initializing graph .. ");

        odb = new OGraphDatabase("local:/home/vagrant/orientdb-graphed-1.5.1/databases/sitepoint-ruby-demo").open("admin","admin");

        //graph = new OrientGraphNoTx(odb);    // <----- THIS BREAKS C++ CODE

        //System.out.println("Initialized ok .. ");

    }

    public static void main(String[] args)
    {
        Inserter ins = new Inserter();
    }
}

Как я могу это исправить??? Есть идеи?

Теги:
orientdb
jni

1 ответ

0

Я думаю, что пропущены бары orientdb в пути класса, недостаточно чертежей api, вам нужно включить также orient-commons.jar и orientdb-core.jar (параметры чертежей-ориентированных графов)

пока

Ещё вопросы

Сообщество Overcoder
Наверх
Меню