Game Development Community

packaging Java games

by Steve Fletcher · in Technical Issues · 02/22/2003 (1:08 pm) · 11 replies

All I want is to have a program that installs the Java program I wrote and have some way to run it after installation.

I used an installation program called Inno Setup to do this. I can install it, but I can't get it to make a shortcut the runs the program (it runs if I open up the directory it's in and run it with a .bat file or whatever though).

I made a program, run.c, that's just a wrapper around javaw because I have an installation program that installs my program and Java - the installation program can't find javaw except when it's installed before the installation program started.

It works fine when I call it with a .bat file from the same folder, using "run Ecoheroes".

However, when I try to call it from a different folder with "{app}\run -cp {app}\ Ecoheroes", where {app} is the folder the program's in, it doesn't work. It doesn't matter whether I do this from a .bat file or from a Windows shortcut - it doesn't work either way.

I've also tried:
{app}\run -cp {app}\ Ecoheroes.class
{app}\run -cp {app}\ {app}\Ecoheroes.class

My C code follows (it's a console app):

#include
#include

int main( int argc, char** argv )
{
int i = 0;
char* cmdline = NULL;
char* temp = NULL;

cmdline = malloc(10000); /* big buffer */
temp = malloc(10000);

if(argc <= 1)
{
printf("It must have at least a class parameter\n");
exit(1);
}

sprintf(cmdline, "javaw");
for(i = 1; i < argc; i++) {
sprintf(temp, "%s", cmdline);
sprintf(cmdline, "%s %s", temp, argv);
}

printf("%s\n", cmdline);
system(cmdline);
return 0;
}

So if anyone has any suggestions, please post them here. I don't even know whether I'm on the right track at all.

- Steve Fletcher

#1
02/23/2003 (6:00 pm)
better still use the JVM Invoker API..gives you much better control... for code samples see the launcher.c code in your jdk src.jar .... i might have some old source code lying around..if you need...

see this link CLICK ME

and the Javasoft web pages
#2
02/25/2003 (3:55 am)
Thanks.

That looks like it should be better than what I was doing before.

- Steve Fletcher
#3
02/25/2003 (6:29 am)
I had some problems with the code at C:\Documents and Settings\Steven\Desktop\java invoke api\Java CodeGuru (none).htm . I copied the header files into the include folder of my compiler, but I got the following errors:

Specified export _JNI_OnLoad@8 is not defined
Specified export _JNI_OnUnload@8 is not defined

I don't know which header file these errors are coming from. I'm going to have to take a look at it on my own computer, where I have actual development tools (specifically, Textpad - which I call a development tool). I don't think I'll figure out what to do, so I figured I'd just ask about it now (since I have a hard time getting on the Internet).

So if anyone knows anything about this, please post something here.

Also, I'm going to have to change it to take the classpath as an argument (well, as several arguments since it may have spaces in it) because I can't have the installation program define the classpath for me - I don't think that even works on Windows XP Professional.

- Steve Fletcher
#4
02/25/2003 (6:40 am)
dude first thing...if you have a jdk...set your compiler's include path to /include and <...>/include/win32


then ..... try and load the JVM_functions as function pointers from jvm.dll using GetProcAddress()....


and then exec them...do not use the jvm.lib cause that ties you to one version of the JVM...


if you still need help drop me a line...
/*
 * Pointers to the needed JNI invocation API, initialized by LoadJavaVM.
 */

#define CREATE_JVM_FUNC "JNI_CreateJavaVM"

//#define 

typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);

//get the address
CreateJavaVM_t CreateJavaVM = (CreateJavaVM_t)GetPRocAddress(hLib,CREATE_JVM_FUNC);



HMODULE hLib = LoadLibrary("<where ver your jre is...>\jre\hotspot\jvm.dll")

JavaVMInitArgs vm_args;
JavaVMOption options[4];

options[0].optionString = "-Djava.compiler=NONE";           /* disable JIT */
options[1].optionString = "-Djava.class.path=c:\myclasses"; /* user classes */
options[2].optionString = "-Djava.library.path=c:\mylibs";  /* set native library path */
options[3].optionString = "-verbose:jni";                   /* print JNI-related messages */

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

/* Note that in the Java 2 SDK, there is no longer any need to call 
 * JNI_GetDefaultJavaVMInitArgs. 
 */
res = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);
if (res < 0) ...
#5
02/26/2003 (5:48 am)
I basically just don't know how to do any of what you've mentioned.

So I guess I'm going to have to figure out something else.

- Steve Fletcher
#6
02/26/2003 (6:08 am)
I can write you the launcher if you want to... :)

probably take like a day or two....
#7
03/01/2003 (5:43 am)
Really? I can't give you anything for doing so.

If you're going to write a launcher, you should probably post the source code (and perhaps the launcher itself) on a website somewhere so that anyone can download it.

I got the installer to set the working directories of the shortcuts and thus managed to get it to work by having shortcuts to batch files that run the game.

That, however, is somewhat unsatisfactory. Your way would be much better, but I'm too inept (when it comes to C, anyways) to implement it myself.

- Steve Fletcher
#8
03/01/2003 (12:23 pm)
hi steve...

its okay..i can just write the code for you free.. :)

one question..can you call methods from a DLL in your setup code...??

then I can give you methods like

RunClass(const char* classPath,const char *className) etc etc...

and you can directly call them from your Installer Scripts...
#9
03/02/2003 (3:27 pm)
Unfortunately, I don't know how to call methods from a DLL. So it would probably have to be a .exe.

I'm sorry. I'm just completely inept when it comes to C. When I first learned to program, I was like "C is the ultimate language. Everything else is pathetic". But then I discovered that I could actually write "real" games in Java. Probably the reason I couldn't do it in C is because I know nothing useful about DLLs and many other important things.

However, I can promise you the following:

the class path will be the current directory (I got the installer to set the working directoy of the shortcuts - which is how I finally managed to get it to work with the batch files).

So you might not really need the class path argument (though maybe you would - I don't really know). It would be nice to have the class path argument because then I could (probably) have the code in a Jar file, but that's not essential.

Thanks alot for doing this.

Hey, if you ever need some Java code (well, Java code that I am capable of writing), post here or send me an email or something.

- Steve Fletcher
#10
03/02/2003 (5:21 pm)
okay

I shall create an exe called JavaTool.exe which shall read its configuration from a file and then you can use it to run as you want.

sample:

To Launch a Class called foo.Bar you shall have to launch

JavaTool -cfgFile=C:\Temp\JavaTool.cfg foo.Bar [param1] [param2] ...

JavaTool.cfg shall look like:

useDefaultJVM=false
JVMDllPath=C:\PAthToJREDir\bin\hotspot\jvm.dll
useCustomClassPath=true
customClassPath=C:\Classes;C:\MyJars\somejar.jar
customJavaOptions=-DfooOption=baz


how does this grab you...?
#11
03/03/2003 (6:22 pm)
I guess that would work fine.

I'll just need to write a C program that creates the config file when run by the installer. That shouldn't be a problem.

- Steve Fletcher