本文整理汇总了C++中JavaVM::DestroyJavaVM方法的典型用法代码示例。如果您正苦于以下问题:C++ JavaVM::DestroyJavaVM方法的具体用法?C++ JavaVM::DestroyJavaVM怎么用?C++ JavaVM::DestroyJavaVM使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JavaVM
的用法示例。
在下文中一共展示了JavaVM::DestroyJavaVM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: main
int main(int cArgs, char *argv[])
{
int optionCount;
int firstOptionOrdinal;
int argCount;
int firstArgOrdinal;
GetCounts(cArgs, argv, optionCount, firstOptionOrdinal, argCount, firstArgOrdinal);
JavaVMOption* options = GetJavaOptions(argv, optionCount, firstOptionOrdinal);
JNIEnv *env;
JavaVM *jvm;
int failureCode = 0;
if ((failureCode = CreateJVM(env, jvm, options, optionCount)) != ErrSuccess) {
fflush(stdout);
return failureCode;
}
if ((failureCode = CallMainMethodOfEntryClass(env, argv, firstArgOrdinal, argCount)) != ErrSuccess) {
fflush(stdout);
return failureCode;
}
// Check for errors.
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
}
// Finally, destroy the JavaVM
jvm->DestroyJavaVM();
return 0;
}
示例3: main
int main( int argc, char *argv[] )
{
JavaVMInitArgs vm_args;
JavaVMOption options[ 1 ];
JavaVM *vm;
JNIEnv *env;
options[ 0 ].optionString = "-Djava.class.path=.";
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.version = JNI_VERSION_1_2;
int res = JNI_CreateJavaVM( &vm, (void **)&env, &vm_args );
if( res < 0 )
{
cerr << "Failed to create VM (" << res << ")" << endl;
return -1;
}
jclass cls = env->FindClass( CLASS_NAME );
// Now try to call main
jmethodID mainMethodID = env->GetStaticMethodID( cls, "main",
"([Ljava/lang/String;)V" );
jclass classString = env->FindClass( "java.lang.String" );
jobjectArray argsToMain =
env->NewObjectArray(0, classString, NULL);
env->CallStaticVoidMethod( cls, mainMethodID, argsToMain );
vm->DestroyJavaVM( );
return 0;
}
示例4: mainprogram
int mainprogram(char *game)
{
FILE *f;
char **paramlines;
int l_paramlines=0;
char prmfile[512];
sprintf_s(prmfile, 512, "../%s/%s.prm", game, game);
if (fopen_s(&f, prmfile, "r") !=0) {
MessageBox(NULL, TEXT("Unable to load parameter file. Please reinstall the program."), TEXT("Error"), MB_OK);
return 0;
} else {
char line[MAX_LINE_LENGTH];
while (fgets(line, MAX_LINE_LENGTH, f)!=NULL) l_paramlines++;
paramlines=new char *[l_paramlines];
fseek(f, 0, SEEK_SET);
int i=0;
while (fgets(line, MAX_LINE_LENGTH, f)!=NULL) {
int len=strlen(line);
for (int j=len-1; j>=0; j--) {
if (line[j]!='\n' && line[j]!='\r') break;
line[j]=0;
}
paramlines[i]=new char[len+1];
strcpy_s(paramlines[i], len+1, line);
i++;
}
}
if (l_paramlines<1) {
MessageBox(NULL, TEXT("Empty parameter file. Please reinstall the program."), TEXT("Error"), MB_OK);
return 0;
}
JavaVM *jvm;
JNIEnv *env;
LoadLibrary(TEXT("jvm.dll"));
JavaVMInitArgs vm_args;
vm_args.version=JNI_VERSION_1_6;
vm_args.nOptions=l_paramlines-1;
vm_args.options=new JavaVMOption[l_paramlines-1];
for (int i=0; i<l_paramlines-1; i++) vm_args.options[i].optionString=paramlines[i];
vm_args.ignoreUnrecognized=false;
jint result=JNI_CreateJavaVM(&jvm, reinterpret_cast<void **>(&env), &vm_args);
if (result!=JNI_OK) return 0;
jclass cls=env->FindClass(paramlines[l_paramlines-1]);
if (cls!=NULL) {
jmethodID mid=env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
jobjectArray args=env->NewObjectArray(1, env->FindClass("java/lang/String"), NULL);
env->SetObjectArrayElement(args,0,env->NewStringUTF(game));
env->CallStaticVoidMethod(cls, mid, args);
}
jvm->DestroyJavaVM();
return 0;
}
示例5:
void
jserver_destroy()
{
JavaVM* jvm = get_jvm();
if (jvm != NULL) {
/* Destroy the Java VM. */
jvm->DestroyJavaVM();
}
}
示例6: main
int main(int argc, char* argv[]) {
JavaVM *jvm;
JNIEnv *env;
// NB: This program requires loci_tools.jar in the same directory.
string classpath = "-Djava.class.path";
const int numJars = 1;
string jars[numJars] = {
"loci_tools.jar"
};
for (int i=0; i<numJars; i++) {
classpath += i == 0 ? "=" : PATHSEP;
classpath += jars[i];
}
cout << "Classpath = " << classpath << endl;
// get the default initialization arguments and set the class path
JavaVMInitArgs vm_args;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
const int numOptions = 1;
JavaVMOption options[numOptions];
options[0].optionString = (char*) classpath.c_str();
//options[1].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_4; // VM version 1.4
vm_args.options = options;
vm_args.nOptions = numOptions;
// load and initialize a Java VM, return a JNI interface pointer in env
if (JNI_CreateJavaVM(&jvm, (void**) &env, &vm_args)) {
cout << "Failed to create the JVM" << endl;
exit(1);
}
// invoke the ImageInfo.main(String[]) method using the JNI
jclass imageInfoClass = env->FindClass("loci/formats/tools/ImageInfo");
cout << "Got ImageInfo class: " << imageInfoClass << endl;
jmethodID mid = env->GetStaticMethodID(imageInfoClass,
"main", "([Ljava/lang/String;)V");
cout << "Got main method: " << mid << endl;
jclass stringClass = env->FindClass("java/lang/String");
cout << "Got String class: " << stringClass << endl;
jobjectArray args = env->NewObjectArray(argc - 1, stringClass, 0);
for (int i=1; i<argc; i++) {
jstring arg = env->NewStringUTF(argv[i]);
env->SetObjectArrayElement(args, i - 1, arg);
}
cout << "Got object array: " << args << endl;
env->CallStaticVoidMethod(imageInfoClass, mid, args);
jvm->DestroyJavaVM();
}
示例7: main
int main(int ac, const char** av)
{
JavaVMInitArgs vmArgs;
vmArgs.version = JNI_VERSION_1_2;
vmArgs.nOptions = 1;
vmArgs.ignoreUnrecognized = JNI_TRUE;
JavaVMOption options[1];
vmArgs.options = options;
options[0].optionString = const_cast<char*>("-Xbootclasspath:[bootJar]");
JavaVM* vm;
void* env;
JNI_CreateJavaVM(&vm, &env, &vmArgs);
JNIEnv* e = static_cast<JNIEnv*>(env);
char mainClass[256];
getMainClass(mainClass, sizeof(mainClass));
jclass c = e->FindClass(mainClass);
if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(ac - 1, stringClass, 0);
if (not e->ExceptionCheck()) {
for (int i = 1; i < ac; ++i) {
e->SetObjectArrayElement(a, i - 1, e->NewStringUTF(av[i]));
}
e->CallStaticVoidMethod(c, m, a);
} else
fprintf(stderr, "Couldn't create array\n");
} else
fprintf(stderr, "java.lang.String not found\n");
} else
fprintf(stderr, "main method not found\n");
} else
fprintf(stderr, "Main class not found\n");
int exitCode = 0;
if (e->ExceptionCheck()) {
exitCode = -1;
e->ExceptionDescribe();
e->ExceptionClear();
}
vm->DestroyJavaVM();
return exitCode;
}
示例8: createServiceProxy
int createServiceProxy(int id) {
JavaVM *jvm; /* representa uma VM Java */
JNIEnv *env; /* ponteiro para a interface de metodos nativos */
jvm = bftsmartdiversity::jvm;
env = bftsmartdiversity::env;
/* invoke the Main.test method using the JNI */
jclass cls = env->FindClass("bftsmart/diversity/ClientWrapper");
if (cls == NULL) {
std::cout << "ERRO no FindClass diversity" << std::endl;
jvm->DestroyJavaVM();
return 0x8100;
}
jint arg = (jint) id;
jmethodID constru = env->GetMethodID(cls, "<init>", "(I)V");
if (constru == NULL) {
std::cout << "ERRO ao construir wrapper getmid" << std::endl;
jvm->DestroyJavaVM();
return 0x8200;
}
bftsmartdiversity::serviceProxy = env->NewObject(cls, constru, arg);
if (bftsmartdiversity::serviceProxy == NULL) {
std::cout << "ERRO ao construir wrapper int. srvprox" << std::endl;
jvm->DestroyJavaVM();
return 0x8201;
}
bftsmartdiversity::invokeOrderedMethod = env->GetMethodID(cls, "invokeOrdered", "([B)[B");
bftsmartdiversity::invokeUnorderedMethod = env->GetMethodID(cls, "invokeUnordered", "([B)[B");
if (bftsmartdiversity::invokeOrderedMethod == NULL || bftsmartdiversity::invokeUnorderedMethod == NULL) {
std::cout << "ERRO ao obter execute(un) ordered " << std::endl;
jvm->DestroyJavaVM();
return 0x8107;
}
return 0x0;
}
示例9: main
int main(int argc, char **argv) {
JavaVM* pJVM = 0;
JNIEnv* env = create_vm(&pJVM);
jint ver = env->GetVersion();
printf("version is : %d\n", ver);
initJavaReference(env);
// check for exceptions
checkException(env);
// destroy
pJVM->DestroyJavaVM();
pJVM = 0;
}
示例10: main
int main(int args, const char * argv[]) {
char optionString[] = "-Djava.class.path=/Users/nerdwizard/Documents/XDU/Salt/SingleDocker/out/production/SingleDocker/";
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];
size_t optionStringSize = strlen(optionString) + 1;
options[0].optionString = new char[optionStringSize];
copy(optionString, optionString + optionStringSize, options[0].optionString);
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = (jboolean) false;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
delete options;
auto className = "org/bedlab/ros/docks/Execute";
if (env == nullptr) {
cerr << "WTF?!" << endl;
return -1;
}
jclass cls = env->FindClass(className);
if (cls == nullptr) {
printJVMException(env);
cerr << className << ": Class Not Found" << endl;
return -1;
}
auto methodName = "execute";
jmethodID mid = env->GetStaticMethodID(cls, methodName, "(Ljava/lang/String) Ljava/lang/String");
if (mid == nullptr) {
printJVMException(env);
cerr << methodName << ": MethodNot Found" << endl;
return -1;
}
string path = string(getcwd(NULL, 0)) + string(argv[1]);
cout << "Working on: " << path << endl;
jstring jpath = env->NewString((const jchar *) path.c_str(), (jsize) path.length());
jstring ret = (jstring) env->CallStaticObjectMethod(cls, mid, jpath);
cout << ">> " << ret << endl;
/* We are done. */
jvm->DestroyJavaVM();
return 0;
}
示例11: invokeOrdered
int invokeOrdered(BFT_BYTE command[], int tamanho, BFT_BYTE saida[]) {
JavaVM *jvm; /* representa uma VM Java */
JNIEnv *env; /* ponteiro para a interface de metodos nativos */
jvm = bftsmartdiversity::jvm;
env = bftsmartdiversity::env;
/* apenas para fins de debug
printf("tamanho: %d\n",tamanho);
for (int i=0;i<tamanho;i++)
{
printf("%x ",command[i]);
}
printf("\n");
fim do debug*/
jbyteArray arrayJava = env->NewByteArray(tamanho);
env->SetByteArrayRegion(arrayJava, 0, tamanho, (jbyte*) command);
jbyteArray result = (jbyteArray) (env->CallObjectMethod(bftsmartdiversity::serviceProxy,
bftsmartdiversity::invokeOrderedMethod, arrayJava));
if (result == NULL) {
std::cout << "erro o chamar invoke ordered" << std::endl;
jvm->DestroyJavaVM();
return 0x8109;
}
jint saidaT = env->GetArrayLength(result);
env->GetByteArrayRegion(result, 0, saidaT, (jbyte*) saida);
/* apenas para fins de debug
printf("tamanho: %d\n",saidaT);
for (int i=0;i<saidaT;i++)
{
printf("%x ",saida[i]);
}
printf("\n");
fim do debug */
return (int) saidaT;
}
示例12: invokeUnordered
int invokeUnordered(BFT_BYTE command[], int tamanho, BFT_BYTE saida[]) {
JavaVM *jvm; /* representa uma VM Java */
JNIEnv *env; /* ponteiro para a interface de metodos nativos */
jvm = bftsmartdiversity::jvm;
env = bftsmartdiversity::env;
jbyteArray arrayJava = env->NewByteArray(tamanho);
env->SetByteArrayRegion(arrayJava, 0, tamanho, (jbyte*) command);
jbyteArray result = (jbyteArray) (env->CallObjectMethod(bftsmartdiversity::serviceProxy,
bftsmartdiversity::invokeUnorderedMethod, arrayJava));
if (result == NULL) {
std::cout << "erro o chamar invoke unordered" << std::endl;
jvm->DestroyJavaVM();
return 0x8109;
}
jint saidaT = env->GetArrayLength(result);
env->GetByteArrayRegion(result, 0, saidaT, (jbyte*) saida);
return (int) saidaT;
}
示例13: main
int main(int argc, char** argv) {
JavaVMInitArgs args;
args.version = JNI_VERSION_1_1;
args.nOptions = 1;
args.options = new JavaVMOption[1];
args.options->optionString = (char*)"/home/benland100/Desktop/sjvm/javatest/";
JavaVM *vm;
JNIEnv *env;
JNI_CreateJavaVM(&vm,(void**)&env,(void*)&args);
delete [] args.options;
//jclass system = env->FindClass("java/lang/System");
//jclass printstream = env->FindClass("java/io/PrintStream");
//jfieldID outID = env->GetStaticFieldID(system,"out","Ljava/io/PrintStream;");
//jobject out = env->GetStaticObjectField(system,outID);
//cout << (int)out << '\n';
//jclass mainclass = env->FindClass("smart/Client");
//jmethodID main = env->GetStaticMethodID(mainclass,"main","([Ljava/lang/String;)V");
//env->CallStaticVoidMethod(mainclass,main,env->NewObjectArray(0,env->FindClass("java/lang/String"),0));
//jobject obj = env->AllocObject(exception);//env->NewObject(exception,einit);
//env->CallVoidMethod(obj,einit);
//jclass test = env->FindClass("fields/subclass");
jclass mainclass = env->FindClass("javatest");
jmethodID main = env->GetStaticMethodID(mainclass,"main","([Ljava/lang/String;)V");
try {
env->CallStaticVoidMethod(mainclass,main);
if (env->ExceptionOccurred() == 0) {
cout << "Executing Success\n";
} else {
cout << "Damn, exceptions...\n";
}
} catch ( ... ) {
}
env->DeleteLocalRef(mainclass);
vm->DestroyJavaVM();
return 0;
}
示例14: main
int main(int argc, char** argv) {
//Creating VM And ENV Variables
JavaVM *vm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption* options = new JavaVMOption[1];
//VM Arguments
options[0].optionString = (char *)"-Djava.class.path=.:jars/netcdfAll-4.5.jar";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = 1;
vm_args.options=options;
// Construct a VM
jint res = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);
//Delete Options
delete options;
//////////////////////////////////////////////////////////////////////////////////////////////////
//array of file names
string fileName[total];
fileName[0]="20130101_0300.gz";
fileName[1]="20130101_0700.gz";
fileName[2]="20130101_1100.gz";
fileName[3]="20130101_0000.gz";
fileName[4]="20130101_0400.gz";
fileName[5]="20130101_0800.gz";
fileName[6]="20130101_1200.gz";
fileName[7]="20130101_0100.gz";
fileName[8]="20130101_0500.gz";
fileName[9]="20130101_0900.gz";
fileName[10]="20130101_0200.gz";
fileName[11]="20130101_0600.gz";
fileName[12]="20130101_1000.gz";
//for(int i=0;i<total;i++)
// fileName[i]="20130101_0000.gz";
clock_t tStart = clock();
//Parallel Execution of for loop to get the size for each file
for ( int i = 0; i < total; i++)
WeatherData::getSize(vm,env,"latitude",fileName[i],dataDir,i);
//Parallel Execution of for loop to get the attributes
for ( int i = 0; i < total; i++)
{
WeatherData::getFloatData(vm,env,"windSpeed",fileName[i],dataDir,capacity[i]);
WeatherData::getFloatData(vm,env,"windDir",fileName[i],dataDir,capacity[i]);
}
//Get Station Ids
for ( int i = 0; i < total; i++)
{
WeatherData::getStringData(vm,env,"stationId",fileName[i],dataDir,capacity[i]);
WeatherData::deleteFile(vm,env,fileName[i],dataDir);
}
WeatherData::calcBins1(windSpeeds,windDirs,stationIds,stationIds[7000]);
//print result in matrix
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 6; j++)
{
printf("%d\t",result[i][j]);
}
printf("\n");
}
//Print Time Taken For Execution
printf("\n\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
// Shutdown the VM.
vm->DestroyJavaVM();
}
示例15: strcmp
//.........这里部分代码省略.........
#endif
#ifdef BOOT_BUILTINS
++ vmArgs.nOptions;
#endif
RUNTIME_ARRAY(JavaVMOption, options, vmArgs.nOptions);
vmArgs.options = RUNTIME_ARRAY_BODY(options);
unsigned optionIndex = 0;
#ifdef BOOT_IMAGE
vmArgs.options[optionIndex++].optionString
= const_cast<char*>("-Davian.bootimage=bootimageBin");
vmArgs.options[optionIndex++].optionString
= const_cast<char*>("-Davian.codeimage=codeimageBin");
#endif
#ifdef BOOT_LIBRARY
vmArgs.options[optionIndex++].optionString
= const_cast<char*>("-Davian.bootstrap=" BOOT_LIBRARY);
#endif
#ifdef BOOT_BUILTINS
vmArgs.options[optionIndex++].optionString
= const_cast<char*>("-Davian.builtins=" BOOT_BUILTINS);
#endif
#define CLASSPATH_PROPERTY "-Djava.class.path="
unsigned classpathSize = strlen(classpath);
unsigned classpathPropertyBufferSize
= sizeof(CLASSPATH_PROPERTY) + classpathSize;
RUNTIME_ARRAY(char, classpathPropertyBuffer, classpathPropertyBufferSize);
memcpy(RUNTIME_ARRAY_BODY(classpathPropertyBuffer),
CLASSPATH_PROPERTY,
sizeof(CLASSPATH_PROPERTY) - 1);
memcpy(RUNTIME_ARRAY_BODY(classpathPropertyBuffer)
+ sizeof(CLASSPATH_PROPERTY) - 1,
classpath,
classpathSize + 1);
vmArgs.options[optionIndex++].optionString
= RUNTIME_ARRAY_BODY(classpathPropertyBuffer);
for (int i = 1; i < ac; ++i) {
if (strncmp(av[i], "-X", 2) == 0
or strncmp(av[i], "-D", 2) == 0)
{
vmArgs.options[optionIndex++].optionString = const_cast<char*>(av[i]);
}
}
if (class_ == 0) {
usageAndExit(av[0]);
}
JavaVM* vm;
void* env;
JNI_CreateJavaVM(&vm, &env, &vmArgs);
JNIEnv* e = static_cast<JNIEnv*>(env);
jclass c = 0;
if (not e->ExceptionCheck()) {
c = e->FindClass(class_);
}
if (jar) {
free(const_cast<char*>(class_));
}
if (not e->ExceptionCheck()) {
jmethodID m = e->GetStaticMethodID(c, "main", "([Ljava/lang/String;)V");
if (not e->ExceptionCheck()) {
jclass stringClass = e->FindClass("java/lang/String");
if (not e->ExceptionCheck()) {
jobjectArray a = e->NewObjectArray(argc, stringClass, 0);
if (not e->ExceptionCheck()) {
for (int i = 0; i < argc; ++i) {
e->SetObjectArrayElement(a, i, e->NewStringUTF(argv[i]));
}
e->CallStaticVoidMethod(c, m, a);
}
}
}
}
int exitCode = 0;
if (e->ExceptionCheck()) {
exitCode = -1;
e->ExceptionDescribe();
}
vm->DestroyJavaVM();
return exitCode;
}