有没有简单的方法从gradle运行jetty 8(比如使用jettyRun)?

时间:2011-11-24 22:46:10

标签: scala maven-2 jetty gradle maven-jetty-plugin

运气不好我需要jetty 8才能正常使用spray / akka(这是scala项目)。
使用jettyRun使用的旧版本时,我收到的错误如下:
java.lang.NoClassDefFoundError:org / eclipse / jetty / continuation / ContinuationListener
是否有可能创建一些简单的任务来完成jettyRun正在做的工作但是使用jetty 8?

在最坏的情况下,我可以使用我正在构建的战争的嵌入式码头版本,但如果有任何问题,我会很高兴看到一些更简单的解决方案......

3 个答案:

答案 0 :(得分:1)

Pitor,你为什么不最后在here添加你的优秀答案?

我在下面修改了它,使用Jetty版本9来依赖war任务,并使用与jetty插件相同的任务名称(即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
}

用法:

gradle jettyRun

答案 1 :(得分:0)

由于我无法在gradle构建级别找到好的解决方案,所以我决定使用嵌入式jetty。这是scala类:

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();
    }
  }
}

然后在build.gradle:

apply plugin: "application"

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

一切正常:)

答案 2 :(得分:0)

我认为答案有点晚了但是我会把它发布给其他人,他们会为了同样的事情而谷歌。

在尝试使用gradle运行scalatra应用程序时,我偶然发现了同样的问题。 我找到了这个插件,它只是有效 - https://github.com/martins1930/jettyMulti