== Packaging

This section describes some packaging and distribution options.

=== Single jar

This is the default deployment option where you create a single jar (a.k.a fat/uber jar) for your
application.

[TIP]
====
The https://jooby.io/#getting-started[jooby-cli] takes care of configures everything for single jar
distribution. Next example shows how to do it in case you created your application manually.
====

.Maven
[source, xml, role="primary", subs="verbatim,attributes"]
----
<build>
  <plugins>
    ...
    <plugin>
        <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
[source, groovy, role="secondary", subs="verbatim,attributes"]
----
plugins {
  ...
  id "com.github.johnrengelman.shadow" version "5.2.0"
  ...
}

...

shadowJar {
  mergeServiceFiles()
}

----

Maven users:

    mvn clean package

Gradle users:

    ./gradlew shadowJar

=== Stork

https://github.com/fizzed/stork[Stork] is packaging, launch and deploy tool for Java apps.

[NOTE]
====
Stork is only available for Maven projects
====

To configure stork:

1) Creates a `src/etc/stork/stork.yml` file (file location is important):

.stork.yml
[source, yaml]
----
# Name of application (make sure it has no spaces)
name: "${project.artifactId}"

# Display name of application (can have spaces)
display_name: "${project.name}"

# Type of launcher (CONSOLE or DAEMON)
type: DAEMON

# Java class to run
main_class: "${application.class}"

domain: "${project.groupId}"

short_description: "${project.artifactId}"

# Platform launchers to generate (WINDOWS, LINUX, MAC_OSX)
# Linux launcher is suitable for Bourne shells (e.g. Linux/BSD)
platforms: [ LINUX ]

# Working directory for app
# RETAIN will not change the working directory
# APP_HOME will change the working directory to the home of the app
# (where it was intalled) before running the main class
working_dir_mode: RETAIN

# Minimum version of java required (system will be searched for acceptable jvm)
min_java_version: "1.8"

# Min/max fixed memory (measured in MB)
min_java_memory: 512
max_java_memory: 512

# Min/max memory by percentage of system
#min_java_memory_pct: 10
#max_java_memory_pct: 20

# Try to create a symbolic link to java executable in <app_home>/run with
# the name of "<app_name>-java" so that commands like "ps" will make it
# easier to find your app
symlink_java: true
----

2) Configure https://github.com/repaint-io/maven-tiles[Maven Tiles] plugin:

.Maven
[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) Run `mvn package`

Stork zip file will be available in the `target` directory.
