dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Aug 25, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Creating a Java VM

Here is the code ready to use and written in C, to create a JDK 1.1 Java Virtual Machine.

 
#include 

 int main()
  {
    JDK1.1InitArgs data;
    JNIEnv    *env;
    JavaVM    *jvm;
    jclass    MyClass;
    jObject   MyObject;
    jMethodID MyMethod;
    jint      Result;
    
    data.version = 0x00010001; /*select version of your jvm, jdk1.1*/
    JNI_GetDefaultJavaVMInitArgs(&data);
    Result=JNI_CreateJavaVM(&jvm,&env,&data);
    if (Result<0)
     {
          printf("Error when creating the JVM...");
     }else{

Here we locate our class and our initialization method ...*/

 
       MyClass = (*env)->FindClass(env,"MyDesiredClass");
       MyMethod= (*env)->GetStaticMethodID(env,MyClass,"AnyMethod");
       (*jvm)->DestroyJavaVM(jvm);
       printf("Exiting Virtual Machine ...");
     }/*end of else*/

  }/*end of code*/
This code creates a VM ready to load a class and execute one of its static methods; &jvm is a pointer to the JVM. We have also the choice of using the function:
 jint JNI_GetCreatedjavaVMs(JavaVM**,jsize,jsize*); 

This allows me to see which VMs are created and select one on the pointers array JavaVM**, although in JDK1.1 no more than one VM is allowed, this would allow me to see if there's a VM created and use it.

Jose Antonio
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date