How to make .exe file for izpack installer .jar file

Muhammad Imran Tariq picture Muhammad Imran Tariq · Apr 13, 2011 · Viewed 10.3k times · Source

I make an installer with izpack. Its in .jar file. I want to make it in .exe file in order to distribute it. How can I do it in an easy way?

Answer

eee picture eee · Apr 13, 2011

Andrew always likes to promote Java Web Start technology from the start :) It is a nice tech. But, you also need to learn the technical parts first before you can start tinkering with it.

Otherwise, you are left with the old-style EXE distribution model as follows...

I am not familiar with Izpack anyway. But, there are similar separate tools to achieve the combined result as to what izPack can do. My favorite EXE creation and installer tools are Launch4J + InnoSetup + Ant task running from Eclipse IDE.

Launch4J is a Java app launcher. InnoSetup is an installation creator Ant task helps developers on build and integration steps.

How to use Launch4J + InnoSetup + Ant build task + Eclipse IDE: http://www.eteks.com/tips/tipCreationExe.html (in French - use Google translate)

When you are thinking of distributing a desktop-based Windows EXE file for a Java app, you also need to think about the target environment. It is fine when you are targeting Windows XP or lesser version. But, it will start to be a major frustration when you want to make it work properly under Windows Vista and Windows 7.

It is best not to store application configurations, temporary files, etc. that require saving into%ProgramFiles% under Windows Vista/Windows 7 as it now becomes a read-only folder. Use user's profile folder for such purpose.

Of course, you can bypass it by running your app with "Run as Administrator" but it involves the following setup:

Windows Vista and Windows 7 have introduced a strict user access policy through the User Access Control (UAC) prompt feature. The software installation must be done using a user account under Administrators group. All folders under the default Windows’ system Program Files are set to read-only and it may cause a problem to non-administrator user accounts when trying to save something in it. To run Java app using a non-administrator user account, the application properties must be set to enable Run as administrator. A shortcut shall be created in the Desktop and be set to enable Run as administrator as well.

How to solve the following issues:

(1) Issue with AppUserModelID Java support in Windows Vista/Windows 7 needs the following solution: Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons

(2) Issue with Run as Administrator for a Java app needs the following solution: Request admin privileges for Java app on Windows Vista

Other than those, you also need to check on %ProgramFiles% when running under 64-bit Windows version. The path is not the same between 32-bit Windows and 64-bit Windows. Under 64-bit Windows, all 32-bit apps will go into %ProgramFiles(x86)%.

So, be careful when using the hard-coded file path value to your Java app's folder and sub-folders that are installed in %ProgramFiles%. It is better to set up a Windows environment variable which can be generated by InnoSetup in the following ISS file snippet. Use Java System.getenv("MYAPP_HOME") to retrieve the variable:

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; Flags: uninsdeletevalue; ValueType: string; ValueName: "MYAPP_HOME"; ValueData: "{app}\"

[Tasks]
Name: modifypath; Description:"Add application directory to your environmental path"; Flags: unchecked

[Run]
Filename: "{app}\MyApp.EXE"; Parameters: """{app}""\"; WorkingDir: "{app}\"; Description: "Run MyApp"; Flags: postinstall nowait skipifsilent

[Code]

const
    ModPathName = 'modifypath';
    ModPathType = 'system';

function ModPathDir(): TArrayOfString;
begin
    setArrayLength(Result, 1)
    Result[0] := ExpandConstant('{app}');
end;
#include "modpath.iss"

Experiment and enjoy!