# Package your application

The package goal allows you to provision a server using Galleon or build a Bootable JAR (an executable fat JAR), execute CLI commands and scripts to fine tune the server configuration, copy some extra content (e.g.: keystore, properties files) to the server installation and finally deploy your application.

By default the server is provisioned in the `target/server` directory.

## Package a JAXRS application

The example below shows how to produce the latest released WildFly server trimmed using ‘jaxrs-server’ Galleon layer.

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <feature-packs>
                            <feature-pack>
                                <!-- Latest released version -->
                                <location>wildfly@maven(org.jboss.universe:community-universe)</location>
                            </feature-pack>
                        </feature-packs>
                        <layers>
                            <!-- Galleon layer allows to trim the installed server to your needs. The 'jaxrs-server'
                            contains the server content required to execute JAXRS applications -->
                            <layer>jaxrs-server</layer>
                        </layers>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## Create a Bootable JAR

The example below shows how to produce the latest released WildFly server trimmed using ‘jaxrs-server’ Galleon layer and packaged as a Bootable JAR.

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <feature-packs>
                            <feature-pack>
                                <!-- Latest released version -->
                                <location>wildfly@maven(org.jboss.universe:community-universe)</location>
                            </feature-pack>
                        </feature-packs>
                        <layers>
                            <!-- Galleon layer allows to trim the installed server to your needs. The 'jaxrs-server'
                            contains the server content required to execute JAXRS applications -->
                            <layer>jaxrs-server</layer>
                        </layers>
                    <bootableJar>true</bootableJar>
                    <!-- Uncomment to produce a hollow JAR -->
                    <!-- <skipDeployment>true</skipDeployment> -->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## WildFly Glow integration

You can configure the plugin to discover the Galleon configuration. Galleon feature-packs and layers required by your deployment(s) are discovered from the deployment(s) binary file(s).

This documentation contains more information on WildFly Glow and the plugin configuration.

Provisioning of a server with discovery enabled. In this example the primary deployment is analyzed to produce the server:

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <discover-provisioning-info/>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## Galleon options

You have the ability to set some optional Galleon options when provisioning a WildFly Server. Galleon options are documented in the Galleon documentation and in the WildFly Galleon plugins documentation.

Galleon options usage example:

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        ...
                        <galleon-options>
                            <!-- Provision a WildFly server that includes features and modules at the preview stability level -->
                            <stability-level>preview</stability-level>
                            <!-- Fork the Galleon provisioning in a separate process -->
                            <jboss-fork-embedded>true</jboss-fork-embedded>
                        </galleon-options>
                    </configuration>
                    ...
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## Fine tune server configuration and package extra content

The example below shows how to configure the plugin goal to execute CLI commands and copy extra content inside the installed server:

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <feature-packs>
                            <feature-pack>
                                <location>wildfly@maven(org.jboss.universe:community-universe)</location>
                            </feature-pack>
                        </feature-packs>
                        <layers>
                            <layer>jaxrs-server</layer>
                        </layers>
                        <packaging-scripts>
                            <!-- Commands and scripts are executed in the context of an embedded-server.
                            You don't need to start and stop the embedded-server. -->
                            <packaging-script>
                                <!-- List of commands -->
                                <commands>
                                    <command>/system-property=org.jboss.example.runtime:write-attribute(name=dev)</command>
                                    <command>/system-property=org.jboss.example.runtime2:write-attribute(name=dev2)</command>
                                </commands>
                                <!-- Properties files containing System Properties to resolve expressions -->
                                <properties-files>
                                    <file>cli.properties</file>
                                </properties-files>
                                <!-- Enable expression resolution prior to send the commands to the server, false by default -->
                                <resolve-expressions>true</resolve-expressions>
                                <!-- List of CLI script files -->
                                <scripts>
                                    <script>config.cli</script>
                                    <script>config2.cli</script>
                                </scripts>
                            </packaging-script>
                        </packaging-scripts>
                        <!-- A list of directory that contains content to copy to the server. Each directory must contain a
                         directory structure that complies with the server directory structure.
                         For example extra-content/standalone/configuration/foo.properties to copy the foo.properties file to
                         target/server/standalone/configuration/ directory -->
                        <extra-server-content-dirs>
                            <extra-content>extra-content</extra-content>
                        </extra-server-content-dirs>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## Deploy your WAR application in the root context

By default the name of the WAR is used as the runtime-name for your deployment. You can specify a runtime-name parameter to tune the context in which your deployment will be registered. In this example we are using the special ‘ROOT.war’ runtime-name to reference the root context.

    <project>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <feature-packs>
                            <feature-pack>
                                <location>wildfly@maven(org.jboss.universe:community-universe)</location>
                            </feature-pack>
                        </feature-packs>
                        <layers>
                            <layer>jaxrs-server</layer>
                        </layers>
                        <name>ROOT.war</name>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>

## Deploying multiple deployments

By default, only the project itself is deployed to the provisioned server. You can add additional deployments by adding a project dependency and including specific, excluding specific or scope based dependencies in your deployment.

The following options can be used to include/exclude dependencies to be deployed to a packaged container:

- `<included-dependencies/>`
- `<excluded-dependencies/>`
- `<included-dependency-scope/>`
- `<excluded-dependency-scope/>`

    <project>
        ...
        <dependencies>
          <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <scope>provided</scope>
          </dependency>
          <dependency>
            <groupId>org.example.jdbc</groupId>
            <artifactId>example-driver</artifactId>
            <version>1.0.0.Final</version>
          </dependency>
          <dependency>
            <groupId>org.example</groupId>
            <artifactId>example-common</artifactId>
            <version>1.0.0.Final</version>
            <type>war</type>
          </dependency>
          <dependency>
            <groupId>org.example</groupId>
            <artifactId>example</artifactId>
            <version>1.0.0.Final</version>
            <type>war</type>
          </dependency>
          <dependency>
            <groupId>org.example.jdbc</groupId>
            <artifactId>example-test-driver</artifactId>
            <version>1.0.0.Final</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
          </dependency>
        </dependencies>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>5.1.0.Final</version>
                    <configuration>
                        <included-dependencies>
                            <included>!org.example.jdbc:*test*</included>
                            <included>org.example.jdbc</included>
                            <!-- Include all WAR's -->
                            <included>::war</type>
                        </included-dependencies>
                        <excluded-dependencies>
                            <excluded>:example-common</excluded>
                        </excluded-dependencies>
                        <excluded-dependency-scope>test</excluded-dependency-scope>
                        <feature-packs>
                            <feature-pack>
                                <location>wildfly@maven(org.jboss.universe:community-universe)</location>
                            </feature-pack>
                        </feature-packs>
                        <layers>
                            <layer>jaxrs-server</layer>
                        </layers>
                        <!-- Defines the name for this projects deployment -->
                        <name>ROOT.war</name>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>package</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
            ...
        </build>
    ...
    </project>