Last active
August 29, 2015 14:04
-
-
Save ScalaWilliam/82ee7d832cc5bfd4d59d to your computer and use it in GitHub Desktop.
Embedded Jetty + Scalatra with Webjars loading (loads META-INF/resources data from the classpath jars). Works without any configuration in Jetty, jetty-maven-plugin, but not so easily in embedded form. Make sure to create websresources/index.html in your src/main/resources/ directory. Examples provided in Scalatra documentation are strange - set…
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
def initialiseApp[T<:LifeCycle](port: Int) = { | |
val server = new Server(port) | |
val context = new WebAppContext() | |
context.setContextPath("/") | |
context.setResourceBase(new File(getClass.getResource("/webresources/index.html").getFile).getCanonicalFile.getParentFile.getCanonicalPath) | |
context.addEventListener(new ScalatraListener) | |
context.addServlet(classOf[DefaultServlet], "/") | |
context.setInitParameter(ScalatraListener.LifeCycleKey, classOf[ConfiguredBootstrap].getCanonicalName) | |
context.setAttribute(WebInfConfiguration.WEBINF_JAR_PATTERN, ".*\\.jar$") | |
context.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*\\.jar$") | |
context.setConfigurations(Array(new WebInfConfiguration, new MetaInfConfiguration)) | |
context.setHandler(new ResourceHandler) | |
server.setHandler(context) | |
server | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment