setup program that makes *.exe ?

I have made a game in java and now want to make a setup program that installs all the files and dirs and have a remove program funktion is there a program that can do this? i want a *.exe file :slight_smile:
/VeNOM

Use NSIS with SuperPimp technology. SuperPimp is so cool, they don’t even tell you what it is. :wink:

As for a program launcher, try this code:


#include <windows.h>

#define MY_APP_NAME "MyApp"
#define MY_APP_EXEC "javaw -jar myapp.jar"


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
      STARTUPINFO startup_info;
    PROCESS_INFORMATION process_info;

      BOOL valid;
      int result;
      LONG key;
      PHKEY openkey;
      LPDWORD type;
      LPBYTE data;

      key = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE/JavaSoft/Java Runtime Environment", openkey);
      key = RegQueryValueEx(openkey, "CurrentVersion", NULL, type, data, 
 
LPBYTE lpData, 
 // address of data buffer 
 
LPDWORD lpcbData 
 // address of data buffer size 
 



      startup_info.cb = sizeof(startup_info);
      startup_info.lpReserved = NULL;
      startup_info.lpDesktop = NULL;
      startup_info.lpTitle = NULL;
      startup_info.dwX = 0;
      startup_info.dwY = 0;
      startup_info.dwXSize = 0;
      startup_info.dwYSize = 0;
      startup_info.dwXCountChars = 0;
      startup_info.dwYCountChars = 0;
      startup_info.dwFillAttribute = 0;
      startup_info.dwFlags = STARTF_FORCEONFEEDBACK;
      startup_info.wShowWindow = 0;
      startup_info.cbReserved2 = 0;
      startup_info.lpReserved2 = NULL;
      startup_info.hStdInput = NULL;
      startup_info.hStdOutput = NULL;
      startup_info.hStdError = NULL;



      valid = CreateProcess(
            NULL, 
            MY_APP_EXEC, 
            NULL, 
            NULL, 
            FALSE, 
            CREATE_DEFAULT_ERROR_MODE, 
            NULL, 
            NULL,
            &startup_info, 
            &process_info 
      ); 
 
      if(!valid)
      {
            result = MessageBox(NULL, "Failed to launch the application. Please make sure that a JVM of 1.3 or higher is installed.", MY_APP_NAME, MB_OK);
      }


 
    return 0;
}

Replace the MY_APP_NAME and MY_APP_EXEC constants with your program’s settings. You can compile with either Visual C++ or with Cygwin GCC. Here’s the voodoo you can use to made GCC work:


g++ -mwindows -mno-cygwin -o MyApp.exe MyApp.cpp

That will create you a windows executable that’s independant of Cygwin.


key = RegQueryValueEx(openkey, "CurrentVersion", NULL, type, data,  

where is the “);” ???

Whoops! I forgot I was modifying that to autodetect the JVM location (shouldn’t be necessary, but I’ve seen some pretty screwed up installations). This one should work better:


#include <windows.h>

#define MY_APP_NAME "MyApp"
#define MY_APP_EXEC "javaw -jar myapp.jar"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        STARTUPINFO startup_info;
        PROCESS_INFORMATION process_info;

        BOOL valid;
        int result;

        startup_info.cb = sizeof(startup_info);
        startup_info.lpReserved = NULL;
        startup_info.lpDesktop = NULL;
        startup_info.lpTitle = NULL;
        startup_info.dwX = 0;
        startup_info.dwY = 0;
        startup_info.dwXSize = 0;
        startup_info.dwYSize = 0;
        startup_info.dwXCountChars = 0;
        startup_info.dwYCountChars = 0;
        startup_info.dwFillAttribute = 0;
        startup_info.dwFlags = STARTF_FORCEONFEEDBACK;
        startup_info.wShowWindow = NULL;
        startup_info.cbReserved2 = 0;
        startup_info.lpReserved2 = NULL;
        startup_info.hStdInput = NULL;
        startup_info.hStdOutput = NULL;
        startup_info.hStdError = NULL;



        valid = CreateProcess(
                NULL, 
                MY_APP_EXEC, 
                NULL, 
                NULL, 
                FALSE, 
                CREATE_DEFAULT_ERROR_MODE, 
                NULL, 
                NULL,
                &startup_info, 
                &process_info 
        ); 
 
        if(!valid)
        {
                result = MessageBox(NULL, "Failed to launch the application. Please make sure that a JVM of 1.3 or higher is installed.", MY_APP_NAME, MB_OK);
        }

        return 0;
}

And for the record (in case I got somethings else wrong) this is the same code that I posted over at JDC a while back. Here’s the link:

http://forum.java.sun.com/thread.jsp?forum=422&thread=360416

yea this one works perfectly :-*

edit: btw i compiled it with dev-c++ (mingw)

Using NSIS you could also launch a java app by getting the java runtime from the registry. Heres a bit to get the current runtime location:


; Check for Java
Function .onInit
  ; Get the Java home directory if installed
  ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
  ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$0" "JavaHome"

  ; Check that Java exists, otherwise inform user and exit
  Strcmp $1 "" 0 continue
    MessageBox MB_OK "Java is not installed on your machine.  Please install the Java Runtime and run this install again."
    Quit
  continue:
FunctionEnd

Now you could create a shortcut to start your app. We will say you have created an executable jar called “mygame.jar” and want a shortcut under Programs called “My Game” with the shortcut called “Start”:


; Create shortcuts
  CreateDirectory "$SMPROGRAMS\My Game"
  CreateShortCut "$SMPROGRAMS\My Game\Start.lnk" "$1\bin\javaw.exe" "-jar mygame.jar" "" ""

yea i tried the “javaw -jar bla.jar blabla” shortcut way too. it works flawlessly.

but i like to have an exe wich does basically the same. just because it could happen that the user accidentially delete the shortcut and doesnt know that he/she just have to doubleclick on the jar to start the program.

well i think the stuff u posted there will be helpfull in the not to distant future.

thx SpongeBob :slight_smile:

And on systems where the file association for jar files is messed up(like mine used 2 be…),
an exe is infinitly better.

Yep. Using the NSIS method I posted is not a better way of doing things, just another way of doing it. It takes alot for granted: (1) Sun JRE is installed and (2) the most current is the one to use.

That is not an issue with the NSIS script I posted. Association of file extensions is in a different part of the windows registry.

Have you tried JavaWebstart, it does not create a .exe, but will let you set an icon & show up in the start menu.

If you want a heavyweight solution, you could try InstallAnywhere. I believe there is a still a free version hanging around.

It creates an installer and executable for multiple platforms. The only problem I’ve noticed is the size of the installer at the end.

Kev

Personally I use Inno Setup:

http://www.jrsoftware.org/isinfo.php

It’s a great simple piece of freeware for making install exes.

This one is free and very much like Install Anywhere
http://www.openinstallation.org/

it is the reference implementation for JSR 38 - Application Installation API Specification