I am developing a Java Game and it will be ran as an Application (Not an Applet), so I would like to make a window/.exe to launch before hand, which has options (E.g. "Play"), although I am completely unsure how to do this.
I would like it to run in the same window as the C++/C# window, but if it cannot and runs by itself, that is fine.
Basically you need to use JNI, but not for Java to call "native" code, for the native code to bootstrap a JVM.
#include <stdio.h>
#include <jni.h>
JNIEnv* create_vm() {
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs args;
JavaVMOption options[1];
/* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purposes of our example. */
args.version = JNI_VERSION_1_2;
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=c:\\projects\\local\\inonit\\classes";
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
JNI_CreateJavaVM(&jvm, (void **)&env, &args);
return env;
}
void invoke_class(JNIEnv* env) {
jclass helloWorldClass;
jmethodID mainMethod;
jobjectArray applicationArgs;
jstring applicationArg0;
helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld");
mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V");
applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
applicationArg0 = (*env)->NewStringUTF(env, "From-C-program");
(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
(*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs);
}
int main(int argc, char **argv) {
JNIEnv* env = create_vm();
invoke_class( env );
}
is one way of doing it, as detailed here.
There are numerous tools which do nothing other than build the executable launcher. One such project (no experience with it, I use JNI directly) is JSmooth. Look to Freecode (formerly freshmeat) and the like for others.
The big differences come into play when you decide you need to do more checking of the environment for proper initialization of latter JVMs, and how much verification you wish to undergo as you marshal the command line parameters from one environment to the next.