Orangevolt ANT Tasks » Tasks
Dynamic commandline exampleExample

2.2.  jstub

jstub creates native executables from jar files.

You never need to create shell scripts to start you application. The only thing which has to be installed is java itself.

New since version 1.1 is support for commandline arguments. They will appended to the given execute string.

Also introduced in version 1.1 is the automatic executable detection for Windows executables (feature proposed by jc dufourd). This feature allows to use a placeholder for the executable inside the given commandline option. The executable evaluates its name and path at runtime and replaces the placeholder before executing them. See the examples.

Version 1.2 introduced new customization features for dynamic commandline parameters. Both enviroment and registry (for win32* modes only :-) expressions can be used in the execute (See chapter Dynamic commandline(s) for details).

Version 1.2 also includes the often requested custom icon feature (for win32* and java modeonly). The icon parameter lets you define a custom icon (provided as gif file) which is patched into the executable as its default icon.

Since version 1.2 you the archive attribute is no more required. This gives you the ability to create executablke wrappers for almost anything !!

Properties

Name Description Required
archive

the zip/jar archive to use.

Since version 1.2 the archive attribute is no more required to give developers the ability to create windows executables executing shell commands.

no
execute

The command line to execute.

When your archive is an regular executable jar file (containing a manifest with guilty main-class attribute) execute has to be java -jar [output] where [output] is the name of the generated executable.

Since Version 1.1 the commandline to execute can contain the placeholder XYZjstubLocationXYZ which is replaced at runtime by path and name of the executable. This feature is Windows specific.

The execute parameter may contain Dynamic commandline(s) which are evaluated at runtime.

Version 1.2: execute can also be defined using a child element <execute>.

yes
icon

The icon parameter defines an executable icon. The icon is used in mode win32, win32-console, java and java-console.

The icon can be provided in any format readable from Java (gif, jpg, png and so on).

The icon SHOULD be provided in 256 color depth. Otherwise the displayed icon may shown incorrect. It is also a good advise to provide the icon with 32x32 pixels. Otherwise it is reduced to 32x32 which may somtimes look ugly.

For windows executables the icon is also patched into the executable binary.

no
mode 3 types of self executables can be created by sfx
  • win32

    Creates a win32 executable (exe file) which is executed without opening a shell window.

  • win32-console

    Creates a win32 executable (exe file) which is executed by opening a shell window. All output goes to the console.

  • unix

    Creates an executable shell script (sh file) which is executed

    1. silent when opened outside a shell
    2. with output when opened in a shell

yes
output The name of the output file (myapp.exe or myapp.sh for example). yes

How does it work ?

The jstub native stubs (written in c) originally contains only a few lines of code -

int main( int argc char** argv)
{
  system( "java -jar %s", (char*)&argv[0]);
    
  return 0;
}

which executes java using the executable as regular jar file.

For win32 and unix modes the zip file will be appended to a native stub (an exe for win32, shell script for unix).

In general the magic behind extraction is the ZLib library. The ZLib library library tries not to read the zip stream at start of file instead the library seeks forward until the zip header signature is found. Is'nt it easy and elegant ?

When i read about zlib and who the hell the ZLib library includes in his software (Adove, Sun etc.) i thought "Why not try to attach an executable as jar file to java ?" - and it works ! You can attach almost any file which has a guilty ZIP header signature inside as jar file to java's classpath.

In short terms: Take any file you want and append a jar file and it will be accepted as regular jar file from java.