当前位置: 首页>>代码示例>>C++>>正文


C++ JNI_CreateJavaVM函数代码示例

本文整理汇总了C++中JNI_CreateJavaVM函数的典型用法代码示例。如果您正苦于以下问题:C++ JNI_CreateJavaVM函数的具体用法?C++ JNI_CreateJavaVM怎么用?C++ JNI_CreateJavaVM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JNI_CreateJavaVM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateJavaVM

void CreateJavaVM(char *classpath, jint (JNICALL *printfn)(FILE *fp, const char *format, va_list args))
{
#ifdef USE_JDK12
	if (!gJavaVM && !gJavaEnv) {

		JavaVMOption options[2];
		JavaVMInitArgs vm_args;

		int	nOptions = 1;

		options[0].name = "classpath";
		if (!classpath)
			options[0].value.p = getenv("CLASSPATH");
		else
			options[0].value.p = classpath;

		if (printfn) {
			options[1].name = "vfprintf";
			options[1].value.p = printfn;
			nOptions++;
		}

		vm_args.version = JNI_VERSION_1_2;
		vm_args.options = options;
		vm_args.nOptions = nOptions;
		vm_args.result = NULL;


		JNI_CreateJavaVM(&gJavaVM, (void **)&gJavaEnv, (void *)&vm_args);
		assert(gJavaVM && gJavaEnv);
	}
#else
	if (!gJavaVM && !gJavaEnv) {
		JDK1_1InitArgs vm_args;
		JNI_GetDefaultJavaVMInitArgs(&vm_args);

		if (!classpath)
			vm_args.classpath = getenv("CLASSPATH");
		else
			vm_args.classpath = classpath;

		if (printfn)
			vm_args.vfprintf = printfn;

		JNI_CreateJavaVM(&gJavaVM, &gJavaEnv, &vm_args);

		assert(gJavaVM && gJavaEnv);
	}
#endif
}
开发者ID:lukfugl,项目名称:raytracer,代码行数:50,代码来源:JavaVM.cpp

示例2: createJVM

JNIEnv* createJVM(){
  if(globalE) {
    return globalE;
  }
  int exitCode = 0;
  int optionsCount = 0;

  JavaVMOption options[5];

  #ifdef BOOT_JAR
    options[optionsCount++].optionString = const_cast<char*>("-Xbootclasspath:[bootJar]");
  #else
    options[optionsCount++].optionString
       = const_cast<char*>("-Davian.bootimage=bootimageBin");
    options[optionsCount++].optionString
       = const_cast<char*>("-Davian.codeimage=codeimageBin");
  #endif
  #ifdef BOOTSTRAP_SO
    options[optionsCount++].optionString =
     const_cast<char*>(BOOTSTRAP_SO);
  #endif

  void* env;
  JavaVMInitArgs vmArgs;
  vmArgs.version = JNI_VERSION_1_2;
  vmArgs.ignoreUnrecognized = JNI_TRUE;
  vmArgs.nOptions = optionsCount;
  vmArgs.options = options;
  JNI_CreateJavaVM(&vm, &env, &vmArgs);
  globalE = static_cast<JNIEnv*>(env);
  return globalE;
}
开发者ID:pserwylo,项目名称:OsmAnd-core,代码行数:32,代码来源:routing_test.cpp

示例3: create_jvm

/// Creates the Java virtual machine.
/// Returns 1 on success and 0 on failure.
int create_jvm(char *classpath) {
	if (jvm == NULL) {
		JavaVMOption options[3];
		JavaVMInitArgs vm_args;

		char destination[200];
		strcpy(destination, "-Djava.class.path=");
		strcat(destination, classpath);
		options[0].optionString = destination;
		options[1].optionString = "-Xms256m";
		options[2].optionString = "-Xmx1024m";

		vm_args.version = JNI_VERSION_1_2;
		vm_args.nOptions = 3;
		vm_args.options = options;
		long status = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);

		if (status != JNI_OK) {
			last_error = ERROR_COULD_NOT_CREATE_VM;
			return FAILURE;
		}

		return SUCCESS;
	}

	return FAILURE;
}
开发者ID:rolandtritsch,项目名称:RustJNI,代码行数:29,代码来源:interface.c

示例4: create_jvm

static void create_jvm()
{
  int i, option_count;
  JavaVMInitArgs vm_args;

  option_count = vmArgsCount + ((classPath != NULL) ? 1 : 0);
  vm_args.version = JNI_VERSION_1_4;
  vm_args.ignoreUnrecognized = JNI_FALSE;
  vm_args.nOptions = option_count;
  vm_args.options = calloc(option_count, sizeof(JavaVMOption));
  for (i = 0; i < vmArgsCount; i++) {
    vm_args.options[i].optionString = vmArgs[i];
    vm_args.options[i].extraInfo = NULL;
  }
  if (classPath != NULL) {
    vm_args.options[i].optionString = create_class_path_option(classPath);
    vm_args.options[i].extraInfo = NULL;
  }

  if (JNI_CreateJavaVM(&jvm, (void**)&mainEnv, &vm_args) != 0)
    errx(50, "JNI_CreateJavaVM() failed");

  mainClass = (*mainEnv)->FindClass(mainEnv, className);
  if (mainClass == NULL)
    errx(50, "Main class not found: %s", className);
  mainMethod = (*mainEnv)->GetStaticMethodID(mainEnv, mainClass, "main", "([Ljava/lang/String;)V");
  if (mainMethod == NULL)
    errx(50, "Main method not found in: %s", className);
  shutdownMethod = (*mainEnv)->GetStaticMethodID(mainEnv, mainClass, "shutdown", "()V");
  if (shutdownMethod == NULL)
    errx(50, "Shutdown method not found in: %s", className);
  reloadMethod = (*mainEnv)->GetStaticMethodID(mainEnv, mainClass, "reload", "()V");
  (*mainEnv)->ExceptionClear(mainEnv); /* Ignore possible exception caused by missing reload() */
}
开发者ID:bmellstrom,项目名称:semeru,代码行数:34,代码来源:semeru.c

示例5: create_destroy_jvm

int create_destroy_jvm() {
	JavaVMOption options[3];
	JavaVMInitArgs vm_args;
	JNIEnv *env;
	JavaVM *jvm;
	long status;

	options[0].optionString = "-Xms512m";
	options[1].optionString = "-Xmx512m";
//	options[2].optionString = "-verbose";

	memset(&vm_args, 0, sizeof(vm_args));
	vm_args.version = JNI_VERSION_1_8;
	vm_args.nOptions = 2;
	vm_args.options = options;
        vm_args.ignoreUnrecognized = JNI_TRUE;

	status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
	
	if (status != JNI_ERR) {
		printf("jvm is created: %p\n", env);
		sleep(3);

		status = (*jvm)->DestroyJavaVM(jvm);
		printf("jvm is destroyed (%d)\n", status);
		sleep(3);
	} else {
		perror("fail to create jvm");
	}

	return 0;
}
开发者ID:crackcraft,项目名称:create_destoy_jvm,代码行数:32,代码来源:test.c

示例6: main

int main(void)
{
  JavaVMInitArgs vmargs;
  JavaVM *vm;
  void *env;
  JavaVMOption myoptions[1];

  /* set up libtool/libltdl dlopen emulation */
  LTDL_SET_PRELOADED_SYMBOLS();
  
  myoptions[0].optionString = concatString("-Xbootclasspath:", getenv("BOOTCLASSPATH"));

  vmargs.version = JNI_VERSION_1_2;
  
  if (JNI_GetDefaultJavaVMInitArgs (&vmargs) < 0)
    {
      fprintf(stderr, " Cannot retrieve default arguments\n");
      return 1;
    }

  vmargs.nOptions = 1;
  vmargs.options = myoptions;

  if (JNI_CreateJavaVM (&vm, &env, &vmargs) < 0)
    {
      fprintf(stderr, " Cannot create the Java VM\n");
      return 1;
    }

  (*vm)->DestroyJavaVM(vm);

  return 0;
}
开发者ID:BillTheBest,项目名称:kaffe,代码行数:33,代码来源:jniBase.c

示例7: main

int main(int argc,char **argv)
{
	JavaVMOption options[1];
	JNIEnv *env;
	JavaVM *jvm;
	JavaVMInitArgs vm_args;
	long status;
	jclass cls;
	jmethodID mid;
	
	options[0].optionString = "-Djava.class.path=.";
	memset(&vm_args,0,sizeof(vm_args));
	vm_args.version = JNI_VERSION_1_2;
	vm_args.nOptions = 1;
	vm_args.options = options;
	status = JNI_CreateJavaVM(&jvm,(void **) &env,&vm_args);

	if (status != JNI_ERR) {
		cls = (*env)->FindClass(env,"Hello");
		if (cls != 0) {
			mid = (*env)->GetStaticMethodID(env,cls,"sayHello","()V");\
			if (mid != 0) {
				(*env)->CallStaticVoidMethod(env,cls,mid,NULL);
			}
		}
	}
    (*jvm)->DestroyJavaVM(jvm);
	return 0;
}
开发者ID:rkalyankumar,项目名称:hellojni,代码行数:29,代码来源:hellojvm.c

示例8: BaseInterface

JavaInterface::JavaInterface( const char *pzComponentPath, const char *pzComponentSettings)
	:	BaseInterface(pzComponentPath, pzComponentSettings)
{
	if (m_jvm)
		return;
	JNIEnv *env;

#ifdef _WIN32
	MS_JDK1_1InitArgs vm_args;
	JNI_GetDefaultJavaVMInitArgs(&vm_args);
	vm_args.nVersion = 0x00010001;
	vm_args.pcszClasspath = (char *)(const char *)m_strComponentPath;
	int nRet = JNI_CreateJavaVM(&m_jvm, &env, &vm_args);
	if (nRet < 0) 
	{
		throw GException("JavaIntegration", 1,nRet);
	}
#else
#ifdef _DYNAMIC_JAVA_LINK_
	JavaVMInitArgs vm_args;
	void *dllHandle = _OPENLIB("libjvm.so");
	if (dllHandle)
	{
	   JavaVMOption options[3];
	   GString strTemp;
	   strTemp.Format("-Djava.class.path=%s",(const char *)m_strComponentPath);
	   options[0].optionString = "-Djava.compiler=NONE"; // disable JIT
	   options[1].optionString = (char *)(const char *)strTemp;
	   vm_args.options = options;
	   vm_args.version = JNI_VERSION_1_2;
	   vm_args.nOptions = 2;
	   vm_args.ignoreUnrecognized = JNI_FALSE;

		void *pfn2 = 0;
		ExceptionHandlerScope duration;
		XML_TRY
		{
			pfn2 = (void *)_PROCADDRESS(dllHandle, "JNI_CreateJavaVM");
		}
		XML_CATCH(ex)
		{
			throw GException("JavaIntegration", 6, getenv("LD_LIBRARY_PATH"));
		}
		if (pfn2)
		{
			cout << "Creating VM\n";
			int nRet = ((fnJNI_CreateJavaVM)pfn2)(&m_jvm, (void **) &env, &vm_args);
			if (nRet < 0) 
			{
				throw GException("JavaIntegration", 1,nRet);
			}
			else
			{
				cout << "Created Java Interpreter\n";
			}
		}
	}
	else
	{
		throw GException("JavaIntegration", 5, getenv("LD_LIBRARY_PATH"));
开发者ID:BrianAberle,项目名称:XMLFoundation,代码行数:60,代码来源:IntegrationJava.cpp

示例9: main

int main(int argc, char **argv)
{

    printf("----> SPACE RACCOONS - We will save you!!!!1\n");

    JavaVM *jvm;
    JNIEnv *env;

    JavaVMInitArgs vm_args;

    JavaVMOption options[4];

    options[0].optionString = "-Xms512M";
    options[1].optionString = "-Xmx1024M";
    options[2].optionString = "-Djava.class.path=com.spaceraccoons.client.jar";
    options[3].optionString = "-Dvisualvm.display.name=SpaceRaccoons";

    vm_args.version = JNI_VERSION_1_6;
    vm_args.options = options;
    vm_args.nOptions = 4;
    vm_args.ignoreUnrecognized = true;

    printf("Initializing Java virtual machine...\n");
    if ((JNI_CreateJavaVM(&jvm, &env, &vm_args)) != JNI_OK)
    {
        // Initialization of the JavaVM failed! :-(
        printf("Initialization of the JavaVM has failed.");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
开发者ID:spaceraccoons,项目名称:spaceraccoons,代码行数:32,代码来源:main.c

示例10: java_vm_create

static caddr_t
java_vm_create (JNIEnv ** java_vm_env)
{
  JavaVMInitArgs vm_args;
  JavaVMOption options[5];
  jint res;
  caddr_t classpath_opt = NULL;
  int inx;
  char *classpath = NULL;

  if (!classpath)
    {
      classpath=getenv ("CLASSPATH");
    }
  if (!classpath)
    {
      classpath= ".";
    }

  classpath_opt = dk_alloc_box (strlen (classpath) + 20, DV_SHORT_STRING);
  sprintf (classpath_opt, "-Djava.class.path=%s", classpath);
  options[0].optionString = classpath_opt;
  vm_args.nOptions = 1;
  vm_args.version = JNI_VERSION_1_2;
  vm_args.options = options;
  vm_args.ignoreUnrecognized = JNI_FALSE;

  res = JNI_CreateJavaVM (&java_vm, (void **) java_vm_env, &vm_args);
  if (res < 0)
    return srv_make_new_error ("42000", "JV002", "Can't create the Java VM");
  else
    return NULL;
}
开发者ID:China-ls,项目名称:virtuoso-opensource,代码行数:33,代码来源:java_skel.c

示例11: create_vm

/*-------------------------------------------------------------------------*
 * NAME
 *   create_vm - create a jvm
 * PARAMETER
 *  argc - number of arguments for the jvm
 *  argv - arguments for the jvm
 *
 * RETURN
 *
 *   NULL -  jvm could not be created
 *   else -  jvm has been created
 *
 * EXTERNAL
 *
 * DESCRIPTION
 *-------------------------------------------------------------------------*/
JNIEnv* create_vm(int argc, char** argv) {
	JavaVM* jvm;
	JNIEnv* env;
	JavaVMInitArgs args;
   int i = 0;
	JavaVMOption* options = (JavaVMOption*)malloc(argc*sizeof(JavaVMOption));
	
	/* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */
	args.version = JNI_VERSION_1_2;
	args.nOptions = argc;
   for(i=0; i < argc; i++) {
      /*printf("jvm_args[%d] = %s\n", i, argv[i]);*/
      options[i].optionString = argv[i];
   }
	args.options = options;
	args.ignoreUnrecognized = JNI_FALSE;

#ifdef DARWIN
   /*
   ** for darwin there exists no JNI_CreateJavaVM, Why not maybe a fix in the future ???
   */
	i = JNI_CreateJavaVM_Impl(&jvm, (void **)&env, &args);
#else   
	i = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
#endif   
   if(i<0) {
      fprintf(stderr,"can not create JVM (error code %d)\n", i);
      env = NULL;
   }
   
   free(options);
	return env;
}
开发者ID:BlueBolt,项目名称:BB_GridEngine,代码行数:49,代码来源:jgdi_test.c

示例12: test_createJVM

int test_createJVM()
{
  JavaVMInitArgs jvm_args;
  JavaVMOption jvm_options[4];

  char* classPathArg = test_buildClassPath();
  int numJVMOptions = 0;
  jvm_options[numJVMOptions].optionString = classPathArg;
  numJVMOptions++;

  char maxHeapOptions[64];
  bool passMaxHeapToJVM = true;
  int maxHeapEnvvarMB = 4096;
  jvm_options[numJVMOptions].optionString = (char *) "-Xmx1024m";
  numJVMOptions++;

  jvm_args.version            = JNI_VERSION_1_6;
  jvm_args.options            = jvm_options;
  jvm_args.nOptions           = numJVMOptions;
  jvm_args.ignoreUnrecognized = 1;

  int ret = JNI_CreateJavaVM(&gp_jvm, (void**)&_tlp_jenv, &jvm_args);
  free(classPathArg);
  return ret;
}
开发者ID:RuoYuHP,项目名称:incubator-trafodion,代码行数:25,代码来源:CheckIfHbaseAvailable.cpp

示例13: main

int main(int argc, char** argv)
{
	(void)argc;
	(void)argv;

	VirtualMachine vm;
	vm.LoadFile("script.as");
	vm.Call("void main()");

	JavaVM *jvm;       /* denotes a Java VM */
    JNIEnv *env;       /* pointer to native method interface */
    JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
    JavaVMOption* options = new JavaVMOption[1];
    options[0].optionString = "-Djava.class.path=/usr/lib/java";
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = false;
    /* load and initialize a Java VM, return a JNI interface
     * pointer in env */
    JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    delete options;
    /* invoke the Main.test method using the JNI */
    jclass cls = env->FindClass("Main");
    jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
    env->CallStaticVoidMethod(cls, mid, 100);
    /* We are done. */
    jvm->DestroyJavaVM();

	std::cout << "Hello World! (C++)" << std::endl;
}
开发者ID:BennyQBD,项目名称:Experiments,代码行数:31,代码来源:main.cpp

示例14: main

int main(int argc, char * argv[]){
    JavaVMInitArgs  vm_args;
    JavaVMOption    *options;
    jint            res;

    options = (JavaVMOption*)malloc(sizeof(JavaVMOption));
    options[0].optionString = "-Djava.class.path=.";

    vm_args.version = 0x00010002;
    vm_args.options = options;
    vm_args.nOptions = 1;
    vm_args.ignoreUnrecognized = JNI_FALSE;

    res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if (res != JNI_OK){
        printf("JNI_CreateJavaVM: %d\n", res);
        return 1;
    }

    printf("Java Initialized\n");

    jobject driver = load_driver("postgresql-9.4-1201.jdbc41.jar", "org.postgresql.Driver");
    if (driver != NULL){
        print_version(driver);
        connect(driver, "jdbc:postgresql:pilif", "pilif", NULL);

        (*env)->DeleteLocalRef(env, driver);
        driver = NULL;
    }

    (*jvm)->DestroyJavaVM(jvm);

    printf("Java destroyed\n");
    return 0;
}
开发者ID:pilif,项目名称:jdbc-playground,代码行数:35,代码来源:test.c

示例15: jvm

Jvm::Jvm(const std::vector<std::string>& options, JNIVersion jniVersion)
  : jvm(NULL),
    env(NULL),
    voidClass("V"),
    booleanClass("Z"),
    byteClass("B"),
    charClass("C"),
    shortClass("S"),
    intClass("I"),
    longClass("J"),
    floatClass("F"),
    doubleClass("D"),
    stringClass(JClass::forName("java/lang/String"))
{
  JavaVMInitArgs vmArgs;
  vmArgs.version = jniVersion;
  vmArgs.ignoreUnrecognized = false;

  JavaVMOption* opts = new JavaVMOption[options.size()];
  for (int i = 0; i < options.size(); i++) {
    opts[i].optionString = const_cast<char*>(options[i].c_str());
  }
  vmArgs.nOptions = options.size();
  vmArgs.options = opts;

  int result = JNI_CreateJavaVM(&jvm, (void**) &env, &vmArgs);
  assure(result != JNI_ERR, env);

  delete[] opts;
}
开发者ID:cloudsyk,项目名称:spark_cpp_api,代码行数:30,代码来源:jvm.cpp


注:本文中的JNI_CreateJavaVM函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。