Skip to content

Instantly share code, notes, and snippets.

@timperrett
Created October 13, 2009 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timperrett/3ad5cd900bbe0012b147 to your computer and use it in GitHub Desktop.
Save timperrett/3ad5cd900bbe0012b147 to your computer and use it in GitHub Desktop.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>RELEASE</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>1024m</maxmem>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>move-main-class</id>
<phase>compile</phase>
<configuration>
<tasks>
<move todir="${project.build.directory}/${project.artifactId}-${project.version}">
<fileset dir="${project.build.directory}/classes/">
<include name="Launcher*.class" />
</fileset>
</move>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Launcher</mainClass>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>org.scala-lang:scala-library</exclude>
<exclude>net.databinder:dispatch-twitter_2.7.5</exclude>
<exclude>net.databinder:dispatch-http_2.7.5</exclude>
<exclude>net.databinder:dispatch-json_2.7.5</exclude>
<exclude>net.databinder:dispatch-oauth_2.7.5</exclude>
<exclude>org.apache.httpcomponents:httpclient</exclude>
<exclude>org.apache.httpcomponents:httpcore</exclude>
<exclude>commons-logging:commons-logging</exclude>
<exclude>commons-codec:commons-codec</exclude>
<exclude>com.xmpie.wsapi.integration:xmpie-scala-lift</exclude>
<exclude>com.xmpie.wsapi.integration:xmpie-scala-icp</exclude>
<exclude>com.xmpie.wsapi.integration:xmpie-scala</exclude>
<exclude>com.xmpie.wsapi:xmpie-endpoints</exclude>
<exclude>javax.xml.parsers:jaxp-api</exclude>
<exclude>com.sun.xml.ws:jaxws-rt</exclude>
<exclude>javax.xml.ws:jaxws-api</exclude>
<exclude>javax.xml.bind:jaxb-api</exclude>
<exclude>javax.xml.stream:stax-api</exclude>
<exclude>javax.activation:activation</exclude>
<exclude>javax.xml.soap:saaj-api</exclude>
<exclude>javax.annotation:jsr250-api</exclude>
<exclude>javax.jws:jsr181-api</exclude>
<exclude>com.sun.xml.bind:jaxb-impl</exclude>
<exclude>com.sun.xml.messaging.saaj:saaj-impl</exclude>
<exclude>com.sun.xml.stream.buffer:streambuffer</exclude>
<exclude>org.jvnet.staxex:stax-ex</exclude>
<exclude>com.sun.xml.stream:sjsxp</exclude>
<exclude>com.sun.org.apache.xml.internal:resolver</exclude>
<exclude>org.jvnet:mimepull</exclude>
<exclude>log4j:log4j</exclude>
<exclude>javax.mail:mail</exclude>
<exclude>commons-httpclient:commons-httpclient</exclude>
<exclude>commons-fileupload:commons-fileupload</exclude>
<exclude>commons-collections:commons-collections</exclude>
<exclude>org.jmock:jmock</exclude>
<exclude>org.hamcrest:hamcrest-core</exclude>
<exclude>org.hamcrest:hamcrest-library</exclude>
<exclude>cglib:cglib</exclude>
<exclude>asm:asm</exclude>
<exclude>org.objenesis:objenesis</exclude>
<exclude>net.liftweb:lift-util</exclude>
<exclude>net.liftweb:lift-record</exclude>
<exclude>net.liftweb:lift-webkit</exclude>
<exclude>net.liftweb:lift-actor</exclude>
<exclude>net.liftweb:lift-mapper</exclude>
<exclude>net.liftweb:lift-widgets</exclude>
<exclude>org.mortbay.jetty:servlet-api</exclude>
<!-- <exclude>javax.servlet:servlet-api</exclude> -->
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/deploy.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<goals>
<goal>assembly</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
import java.io.File;
import java.net.JarURLConnection;
import java.net.URL;
import java.security.ProtectionDomain;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.thread.BoundedThreadPool;
import org.mortbay.thread.QueuedThreadPool;
public class Launcher {
public static void main(String[] args) {
try {
// get the location on the filesystem of this war
ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
// setup a server on port 9090
Server server = new Server();
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
server.setThreadPool(threadPool);
// setup the channel connector
Connector connector = new SelectChannelConnector();
connector.setPort(9090);
connector.setMaxIdleTime(30000);
server.setConnectors(new Connector[]{connector});
// setup the webapp
WebAppContext webapp = new WebAppContext();
webapp.setServer(server);
webapp.setContextPath("/");
webapp.setExtractWAR(false);
webapp.setCopyWebDir(true);
webapp.setWar(location.toExternalForm());
// add this webapp to the server
server.addHandler(webapp);
// set some global server paramaters before we get going
server.setStopAtShutdown(true);
server.setSendServerVersion(true);
// get this show on the road!
server.start();
server.join();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment