Moleboxing Java Programs?

Ok, right now I have a my own stripped JRE and bought Molebox. I thought it was going to be easy but I don’t know the exact procedure.

At first, I used JSmooth then Moleboxed that, I thought it was working but it actually was not using my JVM but one it searched for.

I read a previous thread about making a simple launcher using VC. Then I made a small program that did ShellExecute on the exact JVM, then Moleboxed that, and that didn’t work either.

Can someone guide me on exactly what I can use to make one nice clean EXE for my game? I’m trying to finish it soon.

Thanks very much!

My Molebox config file for Titan:


box.cmdline=
box.encrypt=0
box.packdefault=1
box.pattern=*.*
box.separate=0
box.sepfile=
box.ziplevel=0
dir.addfiles=C:\Projects\Puppy Invaders Deluxe\build\molebox
exe.crc=0
exe.pack=1
exe.packedfilesvisible=1
exe.source=C:\Projects\Puppy Invaders Deluxe\build\molebox\TitanAttacks.exe
exe.target=..\TitanAttacks\TitanAttacks.exe
key.0=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
key.1=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

box.contents~
00 common.jar
00 gamecommerce.jar
00 jorbis.jar
00 lwjgl.jar
00 lwjgl_util.jar
00 spgl-lite.jar
00 TitanAttacks.jar
00 bin\dt_shmem.dll
00 bin\dt_socket.dll
00 bin\hpi.dll
00 bin\java.dll
00 bin\net.dll
00 bin\nio.dll
00 bin\rmi.dll
00 bin\verify.dll
00 bin\zip.dll
00 bin\client\jvm.dll
00 lib\ (and then the entire contents of the JRE lib folder follow basically)
~

Cas :slight_smile:

My launcher exe is based on some code I found years ago but basically it’s just a trivial bit of JNI code to run the game from a directory that contains the bin and lib directories of the JRE. The only important bit in it looks like this:


#include "launcher.h"

static JNIEnv *env;
static jobject jobj = 0;
static JavaVM *vm;

typedef jint (APIENTRY * CreateJavaVMPROC) (JavaVM **pvm, void **penv, void *args);

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
) {


    jint res;
	jclass cls;
    jmethodID mid;
    jobjectArray args;
    JavaVMInitArgs vm_args;
    JavaVMOption options[5];

	options[0].optionString = "-Djava.class.path=patch.jar;TitanAttacks.jar;gamecommerce.jar;spgl-lite.jar;common.jar;jorbis.jar;lwjgl.jar;lwjgl_util.jar";
	options[1].optionString = "-Xmx48m";
	options[2].optionString = "-Xms24m";
	options[3].optionString = "-Xincgc";
	options[4].optionString = "-Dworkdir=.";

	HMODULE jvmdll = LoadLibrary("bin\\client\\jvm.dll");
	if (jvmdll == NULL) {
		messageBox("Failed to load Java dll.");
	}

    vm_args.version = JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 5;
    vm_args.ignoreUnrecognized = TRUE;

	CreateJavaVMPROC CreateJavaVM = (CreateJavaVMPROC) GetProcAddress(jvmdll, "JNI_CreateJavaVM");

    res = CreateJavaVM(&vm, (void **)&env, &vm_args);

    if (res < 0) {
        return 0;
    }

    // Get the main class
    cls = env->FindClass(MAIN_CLASS);

    if (cls == 0) {
        return 0;
    }

    // Get the method ID for the class's main(String[]) function.
    mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");

    if (mid == 0) {
        messageBox("Failed to find the main method.");
        return 0;
    }
        args = env->NewObjectArray(0,
                        env->FindClass("java/lang/String"), NULL);
    env->CallStaticVoidMethod(cls, mid, args);

	return 1;

}

The lwjgl.dll and OpenAL32.dlls live OUTSIDE the Molebox, and are distributed alongside the moleboxed exe.

Cas :slight_smile:

Hi Cas, thanks very much, that was extremely helpful! I did run into two problems that I hope you can help me with.

First, I have your CPP compiling fine and it does run my game properly, but when the launcher exits it also stops the Java right away. So I just see a window blink for a second. If I make the launcher put up a message box and leave it there, the whole game will run fine, but with a message box of course. There must be some way for the launcher or Java to keep the process running even after the launcher quits. Have you encountered this problem before?

Second, can standard Molebox bundle JVM (with DLLs), or I have to buy Molebox Pro? It seems like its only Pro, but I still can’t get the game running with Molebox even with the cheap fix of putting a message box up. Some ending debug info from Molebox Pro evaluation version:

[quote][ 275:04c8] :DLL_LOADER:call to default routine 0x6d7cd0fd
[ 275:04c8] :DLL_LOADER:done with result 0x1
[ 276:04c8] :BOX:CloseFile: ‘JRE\BIN\CLIENT\JVM.DLL’
[ 277:04c8] :WRAPPER:LoadLibrary: jre\bin\client\jvm.dll, handle is 6d6b0000
[ 295:0730] :FakeMainDLL: hDLL 0x6d6b0000, reason 0x2, reserved 0x0,defEPoint 0xcaaf2e19, pzVname 0x962f50
[ 295:0730] :DLL_LOADER: DLL_THREAD_ATTACH (D:\PROJECT\GAME\MAJINWAR 2\FINAL\APP-WIN\jre\bin\client\jvm.dll)
[ 295:0730] :DLL_LOADER:call to default routine 0x6d7cd0fd
[ 296:0730] :DLL_LOADER:done with result 0x1
[/quote]
Thanks very much!

The shouldn’t quit at all - it just starts executing Java when it calls env->CallStaticVoidMethod(cls, mid, args);

You are probably going to need to get Molebox Pro.

Cas :slight_smile:

I got it to stop closing, maybe our configs are different. But I found a JNI function called DetachCurrentThread() that fixes my problem. I now got it working completely, but not with Molebox yet.

I just bought MoleBox Pro and I still can’t get it working it crashes with no message right on CreateJavaVM(). So it was atleast able to find jvm.dll in the EXE. I already emailed Molebox to see if they can give me some clues.

Thanks!