=== Packaging

This section describes the primary options for packaging and distributing your Jooby application.

==== Single Jar (Fat/Uber Jar)

The most common deployment option is creating a single executable "Fat Jar" that contains your application code along with all its dependencies.

[TIP]
====
The link:{uiVersion}/#getting-started[Jooby CLI] automatically configures your project for single jar distribution. The examples below show how to configure it manually if needed.
====

.Maven (Shade Plugin)
[source, xml, role="primary", subs="verbatim,attributes"]
----
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>{mavenShadePluginVersion}</version>
      <executions>
        <execution>
          <id>uber-jar</id>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>${application.class}</mainClass>
              </transformer>
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
----

.Gradle (Shadow Plugin)
[source, gradle, role="secondary", subs="verbatim,attributes"]
----
plugins {
  id "com.github.johnrengelman.shadow" version "8.1.1"
}

shadowJar {
  // Required to merge ServiceLoader files from dependencies
  mergeServiceFiles()
  
  manifest {
    attributes 'Main-Class': "${mainClassName}"
  }
}
----

To build the package:

* **Maven:** `mvn clean package`
* **Gradle:** `./gradlew shadowJar`

==== Stork

https://github.com/fizzed/stork[Stork] is a specialized packaging, launch, and deployment tool for Java applications. It generates platform-specific native launchers (shell scripts or batch files) and organizes your dependencies in a clean directory structure.

[NOTE]
====
The Stork integration is currently only available for Maven projects.
====

To configure Stork:

1. **Create the configuration:** Define a `src/etc/stork/stork.yml` file.

.stork.yml
[source, yaml]
----
# Application name (no spaces)
name: "${project.artifactId}"
display_name: "${project.name}"

# Type of launcher (CONSOLE or DAEMON)
type: DAEMON
main_class: "${application.class}"

# Platforms to generate (LINUX, WINDOWS, MAC_OSX)
platforms: [ LINUX ]

# Directory mode: RETAIN (current) or APP_HOME (switch to app root)
working_dir_mode: RETAIN

# Runtime Requirements
min_java_version: "17"
min_java_memory: 512
max_java_memory: 512

# Create a symbolic link to java as "<app_name>-java" for easier process tracking
symlink_java: true
----

2. **Add the Maven Tiles plugin:** Use the Jooby Stork tile to automate the build.

.pom.xml
[source, xml, subs="verbatim,attributes"]
----
<build>
  <plugins>
    <plugin>
      <groupId>io.repaint.maven</groupId>
      <artifactId>tiles-maven-plugin</artifactId>
      <version>{mavenTilesPluginVersion}</version>
      <extensions>true</extensions>
      <configuration>
        <tiles>
          <tile>io.jooby:jooby-stork:{joobyVersion}</tile>
        </tiles>
      </configuration>
    </plugin>
  </plugins>
</build>
----

3. **Build the package:** Run `mvn package`. The resulting Stork `.zip` file will be located in the `target` directory.
