Java desktop application launcher exe

I have written a JSE desktop application which i want to launch using a launcher exe. So that users are not bothered about the location of the compatible JRE.

(I am not bothered about cross platform issues. I would be happy with a windows only solution :-)

I had written a small C program which uses CreateProcess() Win32 API function to launch a jvm. The path to the jvm will be read from a configuration file created during deployment/installation. But the problem with this approach is the there will be two different process entry in the Windows task manager. One for the launcher and another java.exe process created using the CreateProcess() call.

What i would really like is just a single entry in the Task Manager process list with the name of the launcher displayed and not the java.exe name. This way the user can see in the process list the memory usage and CPU utilization and disk IO information of the application easily.

Is there a way i could write a launcher which satisfies the above requirements.

Note: I have seen the LaunchAnythere java launcher created by InstallAnywhere which does exactly the same thing. I just want to know how they are doing it. Are they using some straight forward Windows API stuff or are they doing little MAGIC there in the launcher? :-)

Thanks in advance

[1346 byte] By [JMembera] at [2007-10-3 3:41:43]
# 1

You can create a JVM in C and run it without using the java.exe (this is actually what the java.exe is doing).

Then when you execute your exe you will only see the launcher process in the task manager.

In order to create a jvm and run it you can use the following example (you will need to add java lib files to the path in order to compile this):

HMODULE jvmDll=NULL;

char* javaHome=getenv("JAVA_HOME");

char* dllLocation=combineStrings(javaHome,"/jre/bin/server/jvm.dll");

jvmDll=LoadLibrary(dllLocation);

FARPROC proc=GetProcAddress(jvmDll,"JNI_CreateJavaVM");

CreateJavaVMPROC JNI_CreateJavaVM=(CreateJavaVMPROC)proc;

JavaVMInitArgs args;

JavaVMOption options[1];

char* classPath="....";

//run process

args.version=JNI_VERSION_1_4;

args.nOptions=2;

options[0].optionString=classPath;

args.options=options;

args.ignoreUnrecognized=JNI_FALSE;

int created=JNI_CreateJavaVM(&jvm,(void **)&env,&args);

jclass mainClass=env->FindClass(className);//this finds the main class based on its name for example (com.mycompany.MyMainClass)

jmethodID mainMethod=env->GetStaticMethodID(mainClass,"main","([Ljava/lang/String;)V");//find main(String[]) method

jobjectArray applicationArgs=env->NewObjectArray(1,env->FindClass("java/lang/String"),NULL);

if(argument!=NULL)//put the command line arguments for the main class (if you have any)

{

jstring stringArgument=env->NewStringUTF(argument);

env->SetObjectArrayElement(applicationArgs,0,stringArgument);

}

env->CallStaticVoidMethod(mainClass,mainMethod,applicationArgs);//class main method

jvm->DestroyJavaVM();//when java app ends, this will destory the jvm (not before)

sushika at 2007-7-14 21:37:35 > top of Java-index,Desktop,Developing for the Desktop...
# 2
and also use FreeLibrary() after destroying the JVM.
shahidshaikha at 2007-7-14 21:37:35 > top of Java-index,Desktop,Developing for the Desktop...