Is there any easy way to run jetty 8 from gradle (like with jettyRun)?
Asked Answered
E

3

3

Unlucky I need jetty 8 to work properly with spray/akka (it's scala project).
With older version used by jettyRun I'm getting error like:
java.lang.NoClassDefFoundError: org/eclipse/jetty/continuation/ContinuationListener
Is it possible to create some simple task to do the job which jettyRun is doing but with jetty 8?

In worst case I can use embedded version of jetty with war which I'm building, but I would be happy to see some simpler solution if there is any...

Evasion answered 24/11, 2011 at 22:46 Comment(0)
E
0

Since I wasn't able to find good solution at the gradle build level I decided to use embedded jetty. Here is scala class:

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.server.bio.SocketConnector

object JettyServer {

  def main(args: Array[String]) {
    val server = new Server
    val context = new WebAppContext
    val connector = new SocketConnector

    connector.setMaxIdleTime(1000 * 60 * 60)
    connector.setPort(8080)

    context.setServer(server)
    context.setWar(args(0))

    server.setConnectors(Array(connector))
    server.setHandler(context)

    try {
      server.start();
      server.join();
    } catch {
      case e: Exception => e.printStackTrace();
    }
  }
}

And then in build.gradle:

apply plugin: "application"

mainClassName = "com.mycompany.myproject"
run.args = [war.archivePath]
task jettyRun(dependsOn: run)

And everything works :)

Evasion answered 26/11, 2011 at 19:33 Comment(0)
W
1

Pitor, why didn't you end up adding your excellent answer from here?

I've adapted it below, to use Jetty version 9, to depend on the war task, and to use the same task name as the jetty plugin (i.e. jettyRun).

configurations {
    jetty
}

dependencies {
    jetty "org.eclipse.jetty:jetty-runner:9.2.11.v20150529"
}

task jettyRun(type: JavaExec, dependsOn: war) {
    main = "org.eclipse.jetty.runner.Runner"
    args = [war.archivePath]
    classpath configurations.jetty
}

Usage:

gradle jettyRun
Wisconsin answered 5/6, 2015 at 3:15 Comment(0)
E
0

Since I wasn't able to find good solution at the gradle build level I decided to use embedded jetty. Here is scala class:

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.server.bio.SocketConnector

object JettyServer {

  def main(args: Array[String]) {
    val server = new Server
    val context = new WebAppContext
    val connector = new SocketConnector

    connector.setMaxIdleTime(1000 * 60 * 60)
    connector.setPort(8080)

    context.setServer(server)
    context.setWar(args(0))

    server.setConnectors(Array(connector))
    server.setHandler(context)

    try {
      server.start();
      server.join();
    } catch {
      case e: Exception => e.printStackTrace();
    }
  }
}

And then in build.gradle:

apply plugin: "application"

mainClassName = "com.mycompany.myproject"
run.args = [war.archivePath]
task jettyRun(dependsOn: run)

And everything works :)

Evasion answered 26/11, 2011 at 19:33 Comment(0)
S
0

I think it's a little late for an answer :) But I'll post it for others who would google around for the same thing.

I stumbled upon the same issue while trying to run a scalatra app with gradle. I found this plugin and it just works - https://github.com/martins1930/jettyMulti

Silicosis answered 29/4, 2013 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.