Escolar Documentos
Profissional Documentos
Cultura Documentos
2 - Getting Started
Before you start packaging up your app with 7zip, you'll probably want to download my
complete example pack. This ZIP file contains everything you'll need to get started, including
a ready to ship JRE (Java 6 Update 16) and an Ant build file. Note that you do not need to
install 7zip; I've packed the necessary 7zip.exe to create the archive with the example pack.
However, if you want to install 7zip, can download the installer hereor from my mirror on
Onyx. This sample pack is also an Eclipse project. If you work out of Eclipse, you can import
the .project inside of the example pack into your Eclipse IDE.
Or, if you want to see the 7zSD.sfx launcher in action, download the pre-built demolauncher.
3 - Fundamentals
Here's how this all works. 7zip (and other ZIP installer type packages) provide SFX launchers.
These launchers are essentially native Windows executables that understand how to extract
an archive to a temporary directory, and launch an application (usually another installer).
This is how the Mozilla Firefox installer works: when you launch the "installer" the extracting
files dialog that opens is actually the 7zip SFX launcher extracting the real "setup.exe" to a
temporary directory. Once done, it starts setup.exe to complete the installation process.
In this case, the basic principle is the same, except I'm using the 7zip SFX launcher to extract
my application and required JRE components to a temporary directory, and then start it.
Producing a native Windows SFX launcher is quite easy; you need to binary concatenate three
files together: the SFX launcher, an app.tag configuration file, and a 7zip archive. In
Windows, using the copy command, this looks something like:
C:\> copy /b 7zSD.sfx + app.tag + app.7z start.exe
This produces start.exe, a portable native Windows app that contains everything your Java
application needs to run in a single executable! When run, start.exe will use 7zSD.sfx to
extract the contents of app.7z to a temporary directory, and launch whatever application
you've defined in app.tag. Pretty freakin' sweet if I say so myself.
The Ant build script in my example pack compiles this app and creates app.jar, a runnable
JAR file.
There's nothing too complicated about the configuration file. In this example, I'm simply
extracting the 7zip file included with the native SFX launcher and starting
launcher\jre\bin\javaw.exe, which is the JRE packaged with the launcher (found under
launcher\jre in the example pack). The %%S property in the configuration file is the directory
that contains the SFX executable (where the user started it from). The %%T property is the
temporary directory where the SFX launcher placed the extracted JRE and application files.
Note that when the Java application exits, the SFX launcher will automatically
delete/cleanup this temporary directory.
This example simply asks 7zSD.sfx to extract and then start launcher\app.jar using
launcher\jre\bin\javaw.exe.
name="src.dir" location="${basedir}/src/com/kolich"/>
name="build.dir" location="${basedir}/build"/>
name="launcher.dir" location="${basedir}/launcher"/>
name="7zip.exe.dir" location="${basedir}/7zip"/>
name="sfx.dir" location="${basedir}/sfx"/>
name="dist.dir" location="${basedir}/dist"/>
You can always manually build the installer package yourself, but why bother if you have an
Ant build file ready to do the work for you? When you run the package.7zipexamplebuild
target in the example build file, the resulting ready to launch executable can be found at
dist\start.exe. Start.exe is your shippable application. Again, no pre-installed Java Runtime
Environment required!
In summary, it's fairly straightforward to bundle and ship the Java Runtime Environment with
your Java application using 7zip SFX. Heck, Sun allows and even tells you how to redistribute
the JRE with your applications (just read the LICENSE file provided with any JRE installation).
In the near future, I plan on converting Cappuccino, a really simple web-server powered by
Restlet, to a 7zip SFX enabled app.
Good luck, and don't hesitate to contact me if you have any questions or concerns. Enjoy!