Created
January 23, 2017 11:40
-
-
Save lldeepakll/3e0567ecef61196d24e7168b0680cc62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Environment variable -> System Variable -> path | |
C:\Program Files\Java\jdk1.8.0_11\jre\bin; | |
C:\Program Files\Java\jdk1.8.0_11\jre\bin\server; | |
C:\Program Files\Java\jdk1.8.0_11\bin | |
<Restart System> | |
Open Visual Studio | |
create c++ empty project | |
open project properties | |
C/C++ -> General -> Additional Include Directories | |
Add | |
C:\Program Files\Java\jdk1.8.0_11\include | |
C:\Program Files\Java\jdk1.8.0_11\include\win32 | |
Linker -> General -> Additional Library Directories | |
Add | |
C:\Program Files\Java\jdk1.8.0_11\lib | |
Linker -> Input -> Additional Dependencies | |
write | |
jvm.lib | |
jawt.lib | |
create a c++ file in Source Files | |
copy & paste below code*/ | |
#include <stdio.h> | |
#include<conio.h> | |
#include<jni.h> | |
#include<iostream> | |
using namespace std; | |
JNIEnv* create_vm(JavaVM **jvm) | |
{ | |
JNIEnv* env; | |
JavaVMInitArgs args; | |
JavaVMOption options; | |
args.version = JNI_VERSION_1_6; | |
args.nOptions = 1; | |
options.optionString = "-Djava.class.path=./"; | |
args.options = &options; | |
args.ignoreUnrecognized = 0; | |
int rv; | |
rv = JNI_CreateJavaVM(jvm, (void**)&env, &args); | |
if (rv < 0 || !env) | |
printf("Unable to Launch JVM %d\n",rv); | |
else | |
printf("Launched JVM! :)\n"); | |
return env; | |
} | |
int main(int argc, char **argv) | |
{ | |
JavaVM *jvm; | |
JNIEnv *env; | |
env = create_vm(&jvm); | |
if(env == NULL) | |
return 1; | |
// Shutdown the VM. | |
jvm->DestroyJavaVM(); | |
_getch(); | |
return 0; | |
} | |
//ENJOY | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment