Skip to content

Instantly share code, notes, and snippets.

@jpertino
Created January 20, 2011 04:29
Show Gist options
  • Save jpertino/787393 to your computer and use it in GitHub Desktop.
Save jpertino/787393 to your computer and use it in GitHub Desktop.
a simple embedded jetty server
@Grab('org.mortbay.jetty:jetty-embedded:6.1.26')
import static org.mortbay.jetty.Handler.DEFAULT
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.Context
import org.mortbay.jetty.servlet.DefaultServlet
import org.mortbay.servlet.MultiPartFilter
import groovy.servlet.GroovyServlet
import groovy.servlet.TemplateServlet
new Server(80).with {
new Context(it, '/', Context.SESSIONS).with {
resourceBase = '.'
addFilter MultiPartFilter, '/*', DEFAULT
addServlet(DefaultServlet, '/static/*').with {
setInitParameter 'dirAllowed', 'true'
}
addServlet(TemplateServlet, '/view/*').with {
setInitParameter 'resource.name.regex', '/view(.*)'
setInitParameter 'resource.name.replacement', 'gsp/$1.gsp'
}
addServlet(GroovyServlet, '/groovy/*').with {
setInitParameter 'resource.name.regex', '/groovy(.*)'
setInitParameter 'resource.name.replacement', 'groovy/$1.groovy'
}
}
start()
join()
}
@newgeekorder
Copy link

nice one.. jetty embedded can be a pain!! Many Thanks

@aura-automation
Copy link

great! thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment