簡體   English   中英

從C ++進行JNI調用,FindClass和導入

[英]JNI call from C++ , FindClass & import

我正在使用JNI從C ++訪問Java類,但是只要我在Java文件中調用某個方法(請參見Java代碼), FindClass始終返回nil 當我刪除呼叫時,它工作正常。

./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();
    }
}

我怎樣才能解決這個問題??? 任何想法?

我認為錯過了classpath中的orientdb jars,還不夠藍圖api,還需要包括orient-commons.jar和orientdb-core.jar(blueprints-orient-graph依賴項)

再見

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM