How to launch jetty 7+ with a specified war using groovy / gradle?

I want to run Jetty 7+ using the gradle build, but unfortunately there is no way to do this with jettyRun. Therefore, probably the simplest idea to achieve what I want would be to use a custom purpose:

task runJetty << { def server = new Server() // more code here server.start() server.join() } 

No luck, I just started with gradle, and I don’t know groovy either, so it’s hard for me to create the right target. I looked through the Internet, but I could not find a solution. Can someone hit me with some groovy code sample that can run an existing jar with a pier?

+8
jetty groovy gradle war embedded-jetty
source share
4 answers

Ok, I learned how to start it using jetty directly from the repository:

 jettyVersion = "8.1.0.RC0" configurations { jetty8 } dependencies { jetty8 "org.mortbay.jetty:jetty-runner:$jettyVersion" } task runJetty8(type: JavaExec) { main = "org.mortbay.jetty.runner.Runner" args = [war.archivePath] classpath configurations.jetty8 } 
+14
source share

Here's a working version using ant berth tasks. This finally allowed me proper control with deamon = true.

 configurations { jetty } dependencies { jetty 'org.eclipse.jetty:jetty-ant:9.0.4.v20130625' } task jetty(dependsOn: build) << { ant.taskdef(name: 'jettyRun', classname: 'org.eclipse.jetty.ant.JettyRunTask', classpath: configurations.jetty.asPath, loaderref: "jetty.loader") ant.typedef(name: "connector", classname: "org.eclipse.jetty.ant.types.Connector", classpath: configurations.jetty.asPath, loaderref: "jetty.loader") ant.jettyRun(daemon:true, stopPort: 8999, stopKey: "STOP") { webApp(war: THE_WAR_PRODUCING_TASK.archivePath, contextPath: '/context') connectors { connector(port: 9000) } systemProperties { systemProperty(name: 'environment.type', value: 'development') } } } task jettyStop << { ant.taskdef(name: 'jettyStop', classname: 'org.eclipse.jetty.ant.JettyStopTask', classpath: configurations.jetty.asPath) ant.jettyStop(stopPort: 8999, stopKey: "STOP") } 
+3
source share

There is an eclipse plugin that allows you to launch newer versions of the marina https://github.com/Khoulaiz/gradle-jetty-eclipse-plugin

+3
source share

Planning plug-in supports berth 6.1.25 currently

You can use something like this:

 jettyRoot = '/path/to/your/jetty/root' task runJetty7 << { description = "Runs jetty 7" ant.java(dir: jettyRoot, jar: jettyRoot + '/start.jar', failOnError: 'true', fork: 'true') { classpath { ... } } } 
+1
source share

All Articles