Deploy your .war archive

If the result of your maven build results in a .war file, a little additional work is required.

Add the webapp-runner as dependency

To correctly execute your war file, we need you to add the webapp-runner dependency to your pom.xml file. This dependency let us start your application by starting Tomcat in a command.

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.3</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals><goal>copy</goal></goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>com.github.jsimone</groupId>
                <artifactId>webapp-runner</artifactId>
                <version>7.0.57.2</version>
                <destFileName>webapp-runner.jar</destFileName>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Define your Procfile

To tell use how to start your application, you need to create a Procfile file at the root of your project: more doc about Procfiles

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

That’s it, commit your pom.xml and your Procfile and your app will deploy in the blink of an eye.

Cleanup your application image

When you prepare a war archive from your application. Every dependency is packaged into it and the war file should be almost autonomous. You don’t need too keep all your build dependencies in your application image.

To do so, create a .slugingore file and list the directories which are not essential to your application.

Example

Once built, a Java application will contain the following file tree structure:

my-app/src
my-app/target
my-app/target/classes
my-app/pom.xml
target/my-app.war
.m2/
.jdk/
pom.xml
Procfile
.slugingore
.gitignore

For instance, the .slugignore file may contain:

.m2

As a result, all the maven local repository will be excluded from the application image.


Suggest edits

Deploy your .war archive

©2024 Scalingo