# Deploy/Undeploy Examples

#[[##]]# Deploying your application

The plugin goals [deploy](./deploy-mojo.html), [undeploy](./undeploy-mojo.html),
and [redeploy](./redeploy-mojo.html) can be used to deploy, redeploy and undeploy applications
to a ${appServerName}. The first step is to add the appropriate configuration
to your plugin configuration in the POM.

```xml
<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>
```

The file listed under the `filename` parameter can be deployed to the server using the `[deploy](./deploy-mojo.html)`
goal.

```
  mvn ${pluginPrefix}:deploy
```

The file can later be redeployed or undeployed using the appropriate goals.

```
  mvn ${pluginPrefix}:redeploy
  mvn ${pluginPrefix}:undeploy
```

You can also set the deployment operation to execute at a specific phase, for example the `install` phase.

```xml
<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>
```

#[[##]]# Deploying other artifacts

It is also possible to deploy other artifacts that are not related to your deployment, e.g. database drivers:

```xml
<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy-artifact</goal>
                        </goals>
                        <configuration>
                            <groupId>postgresql</groupId>
                            <artifactId>postgresql</artifactId>
                            <name>postgresql.jar</name>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>
```

The artifact must be already listed as a dependency in the projects' pom.xml.

#[[##]]# Undeployments using Regex-Pattern.

You are allowed to perform undeployments based on a regex-pattern. This is useful as soon as you use
a version identifier within your deployment name. An existing deployment is matched by regex and replaced by
the new one. This example below will undeploy the deployment starting with "postgres-".

```xml
<project>
  ...
  <build>
      ...
      <plugins>
          ...
          <plugin>
              <groupId>${project.groupId}</groupId>
              <artifactId>${project.artifactId}</artifactId>
              <version>${project.version}</version>
              <executions>
                  <execution>
                      <phase>clean</phase>
                      <goals>
                          <goal>undeploy-artifact</goal>
                      </goals>
                      <configuration>
                          <groupId>postgresql</groupId>
                          <artifactId>postgresql</artifactId>
                          <version>2.1.0</version>
                          <type>jar</type>
                          <name>postgresql-2.1.0.jar</name>
                          <match-pattern>postgresql-.*</match-pattern>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          ...
      </plugins>
      ...
  </build>
...
</project>
```

In case multiple deployments match the specified pattern you can decide, how the plugin should behave. You
have the following options:

 * first: The first artifact is taken for undeployment. Other artifacts won't be touched.
          The list of artifacts is sorted using the default collator.
 * all: All matching artifacts are undeployed.
 * fail: Default, Deployment fails.


#[[##]]# Deploying your application in domain mode.

Deploying in domain mode works the same as the examples above, except you need to add the `<server-groups>` property as
well as specify at least one server group.

```xml
<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <configuration>
                    <server-groups>
                        <server-group>main-server-group</server-group>
                    </server-groups>
                </configuration>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>
```