Skip to content

Instantly share code, notes, and snippets.

@alanfranz
Created October 20, 2011 13:09
Show Gist options
  • Save alanfranz/1301100 to your computer and use it in GitHub Desktop.
Save alanfranz/1301100 to your computer and use it in GitHub Desktop.
Heroku Java Webapp War Deployment
?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>artifact</artifactId>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>7.4.5.v20110725</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>7.4.5.v20110725</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>7.4.5.v20110725</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
<configuration>
<assembleDirectory>target</assembleDirectory>
<generateRepository>true</generateRepository>
<programs>
<program>
<mainClass>root.StartWebApp</mainClass>
<name>webapp</name>
</program>
</programs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
web: sh target/bin/webapp
package root;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class StartWebApp {
public static void main(String[] args) throws Exception {
String portStr = System.getenv("PORT");
int port = (portStr == null) ? 8085 : Integer.parseInt(portStr);
Server server = new Server(port);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
// change the name of the war as needed.
webapp.setWar("target/classes/mywebapp.war");
server.setHandler(webapp);
server.start();
server.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment