Do it with help of JNI - Java Native Interface.
You can from a C program load and initialize a JVM and then tell it to load
and execute what class you want.
I bought a book on the subject (somebody borrowed it friday but I will get
back thursday) which was quite good. The only problem with the book was
that it targeted jdk 1.1 and not 1.2, but I got it working anyway.
The following code has been used in my Windows NT Java Service:
void JavaService::serviceThread()
{
JNIEnv *jniEnv;
JavaVMInitArgs vm_args;
JavaVMOption options[6];
string javadblogString = "-Djavadblog=" + m_javadblog;
string classpathOption = "-Djava.class.path=" + m_classpath;
string initialHeapSizeOption = "-Xms" + m_initialHeapSize + "m";
string maxHeapSizeOption = "-Xmx" + m_maxHeapSize +"m";
options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = (char *) javadblogString.c_str();
options[2].optionString = "vfprintf";
options[2].extraInfo = NULL;
options[3].optionString = (char *) classpathOption.c_str();
options[4].optionString = (char *) initialHeapSizeOption.c_str();
options[5].optionString = (char *) maxHeapSizeOption.c_str();
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 6;
vm_args.ignoreUnrecognized = JNI_FALSE;
// Create the virtual machine
if(JNI_CreateJavaVM(&m_javaVM,(void **)&jniEnv,&vm_args) < 0)
{
m_errorState = JSE_UnableToCreatingJavaVM;
m_currentState = JSS_Stopped;
SetEvent(m_startEventSemaphore);
return;
}
// Locate the class
string localClassname = dotsToSlashes(m_classname);
jclass clazz = jniEnv -> FindClass((char *)localClassname.c_str());
if(clazz == 0)
{
m_javaVM -> DestroyJavaVM();
m_errorState = JSE_UnableToFindClass;
m_currentState = JSS_Stopped;
SetEvent(m_startEventSemaphore);
return;
}
// Locate 'startService' method of class
jmethodID mid;
if( (mid = jniEnv -> GetStaticMethodID(clazz,"startServiceManager","()V"))
== 0)
{
m_javaVM -> DestroyJavaVM();
m_errorState = JSE_UnableToFindMethodID;
m_currentState = JSS_Stopped;
SetEvent(m_startEventSemaphore);
return;
}
// Invoke 'startService' method of class
jniEnv -> CallStaticVoidMethod(clazz,mid,NULL);
// Change state to running
m_currentState = JSS_Running;
// Signal that we are finished initialize
SetEvent(m_startEventSemaphore);
// Sleep until we are signaled to stop
WaitForSingleObject(m_stopEventSemaphore,INFINITE);
// Locate 'stopService' method of class
if( (mid = jniEnv -> GetStaticMethodID(clazz,"stopServiceManager","()V"))
== 0)
{
m_javaVM -> DestroyJavaVM();
m_errorState = JSE_UnableToFindMethodID;
m_currentState = JSS_Stopped;
return;
}
// Invoke 'stopService' method of claass
jniEnv -> CallStaticVoidMethod(clazz,mid,NULL);
// Terminate the virtual machine
m_javaVM -> DestroyJavaVM();
// Change state to stopped
m_currentState = JSS_Stopped;
SetEvent(m_stoppedEventSemaphore);
}
Best regards
Christian
-----Oprindelig meddelelse-----
Fra: Sanjay [SMTP:[EMAIL PROTECTED]]
Sendt: 24. november 1999 08:34
Til: [EMAIL PROTECTED]
Emne: How do I convert Java application to EXE ? (off topic)
How can I convert my Java application (total 3 class files) to a EXE file
on WindowsNT ?
Sorry for the off-topic Qs, but since I could not get the information
anywhere else I thought to put it up here......Please help me out
guys......
Thanx a lot,
Sanjay Karanjkar
Systems Engg.
Tata Infotech Ltd.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html