Say Hello To Snug
Chapter 1

Your First Snug Application

This first exercise is for anyone who wants to see Snug working before learning about its configuration options. You can follow it even if you have never built a Java application before.

You may have written a Java application yourself, created one with an AI assistant, or arrived here without an application of your own. We will use the existing Snug JavaFX demonstration application so that everyone starts with the same files. The goal is to create and run a Windows executable first; the explanations of JAR files, runtimes, and packaging will make more sense once you have seen the result.

Your first Snug build

For this first build, you will download Snug and the prebuilt Snug JavaFX demonstration JAR, create a Windows executable using the Snug Quick Build helper, and then run it. You do not need to compile Java code or open a terminal:

  1. Open the latest Snug release page and select the Windows x64 ZIP file from its Assets list:

    https://github.com/synapticloop/snug/releases/latest/ 
  2. Extract the ZIP file to a folder.

The unzipped folder will have the following icons:


snug.exe

Builds Windows executables from Java applications


Snug Quick Build.exe

Lets you build an executable by dragging a JAR file onto it


snug_preview.exe

Lets you preview Snug's launcher dialogs.

For this exercise, we will use Snug Quick Build. The other tools are explained later in the book.

  1. Download the existing Snug JavaFX demonstration JAR and place it in the extracted Snug folder. A JAR is the file containing the Java application; for this exercise, you do not need to know how it was made. Download the demonstration file from:

    https://github.com/synapticloop/snug/blob/main/assets/snug-javafx-demo-windows.jar

On the GitHub file page, click “Download raw file” to save the JAR.


Image: Click the Download raw file icon to download the demonstration JAR.

Your folder should now look like the following:


Image: The extracted Snug folder, with the Snug Quick Build helper (Snug Quick Build.exe), the Snug builder (snug.exe), Snug Preview (snug_preview.exe), and the demonstration JAR (snug-javafx-demo-windows.jar).

  1. Drag the JAR file onto Snug Quick Build.exe.
  2. To drag a file, point at the JAR file, hold down the left mouse button, move the pointer over Snug Quick Build.exe, and release the mouse button.

Image: The demonstration JAR being dragged onto Snug Quick Build.exe.

  1. Wait for Snug Quick Build to finish creating the Windows executable. A new file named Example Application Name.exe should appear in the same folder. Note: This is the default filename used by Snug Quick Build. If no EXE appears, open snug-build.log in the same folder in Notepad and check the Quick Build error before continuing.
  2. Double-click Example Application Name.exe to run it. If a compatible Java runtime is not already available, Snug may ask permission to download one. Follow the on-screen instructions. Once a suitable runtime is available, the demonstration application should open.

Image: The new application "Example Application Name.exe" (outlined in green) from the Snug Quick Build helper.

What just happened?

A JAR contains the Java application you started with. The Snug Quick Build helper uses the normal Snug builder to turn it into a Windows executable (.exe).

For now, getting your first executable to run is enough.

Where to go next

You now have a working Windows executable. If you want to give your application its own name, icon, and other settings, continue to Section 2: Building with Snug, where we introduce the normal Snug builder.

~ ~ ~ * ~ ~ ~

If you simply wanted to try Snug, you can stop here.

~ ~ ~ * ~ ~ ~

TABLE OF CONTENTS

Your First Snug Application        2

Where to go next        5

SECTION 1:
ABOUT THIS BOOK        10

About This Book        11

Why Snug?        11

What Snug Offers        12

What Snug Does Not Do        13

SECTION 2:
BUILDING WITH SNUG        15

Building an Application with Snug        16

The Builder and Launcher        16

Before You Begin        16

Quick-Start: Hello Snug JavaFX        16

That's It        20

Packaging Your Own Application        21

SECTION 3:
CUSTOMISING THE SNUG USER EXPERIENCE        23

The Snug Experience        24

What Happens When Someone Double-Clicks?        24

Application Identity        25

Introducing the snug.options File        26

The Application Icon        27

The Splash Screen        29

SECTION 4:
CONFIGURATION OPTIONS        31

How Snug Configuration Works        32

Input and Output        33

Application Identity        36

Changing the Cache Location        37

Application Metadata        37

Java Runtime        39

Application Instance Behaviour        41

Splash Screen Configuration        41

Runtime Download Behaviour        42

Launcher Messages and Localisation        44

Creating Localisation Files        45

Windows Manifest        46

Build and Diagnostic Tools        46

Using a Different Options File        48

A Practical Configuration Workflow        50

Putting It Together        51

SECTION 5:
CUSTOMISING LAUNCHER MESSAGES        53

Your First Message Change and Preview        54

Understanding Launcher Dialogs        55

Customising the Messages        56

Common Localisation Key Suffixes        60

The Runtime Installation Dialogs        60

When Snug Cannot Launch        62

Message Key Reference        62

Replacement Tokens and the Key Reference        68

Keys Without Replacement Tokens        73

Previewing Your Changes        75

Other Languages        76

Before You Build: Final Checks        77

SECTION 6:
MANAGING YOUR SNUG PROJECT        78

Managing Your Snug Project        79

What Should Go in the snug Directory?        79

What Should Be Saved with the Project?        80

Using Git        80

Should snug.exe Be Committed?        80

A Practical Starting Point        81

Reproducible Builds        81

Automating the Build        82

SECTION 7:
TECHNICAL DETAILS        83

Snug Technical Details        84

What Snug Actually Builds        84

The Builder and the Launcher        85

Anatomy of the Windows Executable        86

The Java Application Remains a JAR        88

What Happens When the Executable Starts        88

Application Identity and the Cache        89

Finding a Java Runtime        92

Starting Java        93

When the Java Application Exits        94

Application Arguments        94

The Windows Manifest        95

Logging and Diagnostics        96

Troubleshooting a Launch        97

Code Signing Is Separate from Packaging        97

Why Snug Does Not Bundle Everything        98

Keeping the Layers Separate        98

Technical Details Will Evolve        100

SECTION 8:
APPENDICES        101

Command-Line Options Reference        102

Quick Overview: Common Builder Options        102

Command-Line Practical Reference        105

Snug Builder (snug.exe) Options Reference        108

Snug Preview (snug_preview.exe) Options Reference        125

Building Snug from Source        127

Why Build Snug Yourself?        127

Before You Begin        127

Obtaining the Source Code        128

Understanding the Project Layout        128

Building the Complete Windows Release        129

Building Individual Components with Cargo        130

Running Tests and Checks        131

Checking the Result        131

Common Build Problems        132

Making Changes and Contributing        132

A Note About Versions        132

Definitions        133

Copyright, Licensing, and Third-Party Notices        140

Copyright Notices        140

Copyright and Licensing        140

Snug        141

Third-Party Software        141

About Snug        142

Why Is It Called Snug?        142

Afterword: On Documentation        143

End Plate        145