Sample code for 30+ languages & platforms
Java

Create Self-Extracting Executable (Windows-only)

Demonstrates how to create a Windows self-extracting EXE.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.ProgressListener;
import com.chilkatsoft.chilkat2.Zip;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Zip zip = new Zip();
        zip.setProgressListener(new ProgressListener() {
            // Called periodically while a method runs (every HeartbeatMs milliseconds).
            @Override
            public boolean abortCheck() {
                return false;   // return true to abort the method in progress
            }

            @Override
            public boolean percentDone(int percentDone) {
                System.out.println("Percent Done: " + percentDone);
                // Explicitly abort at 25% or greater.
                // Remove this to allow for the HTTP download to run to completion.
                if (percentDone > 25) {
                    return true;   // abort the method in progress
                }
                return false;   // return true to abort the method in progress
            }

            @Override
            public void progressInfo(String name, String value) {
                System.out.println(name + ": " + value);
            }
        });

        // Initialize the zip object.  Because we're creating
        // a self-extracting EXE in this example, the filename
        // passed to NewZip will never actually be created.
        try {
            zip.newZip("notUsed.zip");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Append a directory tree.  The AppendFiles does
        // not read the file contents or append them to the zip
        // object in memory.  It simply appends references
        // to the files so that when WriteExe (or WriteZipAndClose,
        // or WriteZip, etc.) is called, the files are compressed
        // and added to the archive.
        boolean recurse = true;
        zip.appendFiles("c:/temp/a/*", recurse);

        // Write "sfx.exe"
        try {
            zip.writeExe("c:/temp/sfx.exe");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }
    }
}