Created
October 25, 2012 09:26
-
-
Save BowlingX/3951613 to your computer and use it in GitHub Desktop.
Sample Scala Main with embedded Jetty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bowlingx.run | |
import org.eclipse.jetty.server.Server | |
import org.eclipse.jetty.webapp.WebAppContext | |
import com.bowlingx.util.Logging | |
/** | |
* This describes our Main Entry point to launch YourApp | |
* Launches an embedded Jetty Server | |
*/ | |
class YourAppLauncher(name: String, version: String, datetime: String) extends App with Logging { | |
import logger._ | |
val thisArgs = if (0 == args.size) { | |
// Default Arguments: | |
Array("8080") | |
} else args | |
val Array(port) = thisArgs | |
val server = new Server(port.toInt) | |
val context = getClass.getClassLoader.getResource("webapp").toExternalForm | |
info("Starting %s; Version: %s, Build @ %s" format(name, version, datetime)) | |
info("Booting WAR Context: %s" format context) | |
val root = new WebAppContext(context, "/") | |
Runtime.getRuntime.addShutdownHook(new Thread() { | |
override def run() { | |
info("Stopping %s" format name) | |
server.stop() | |
} | |
}) | |
server.setHandler(root) | |
server.start() | |
server.join() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment