有没有简单的方法从gradle运行jetty 8(如jettyRun)? [英] Is there any easy way to run jetty 8 from gradle (like with jettyRun)?

查看:150
本文介绍了有没有简单的方法从gradle运行jetty 8(如jettyRun)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我需要jetty 8才能正常使用spray / akka(它是scala项目)。

使用jettyRun使用的旧版本时,出现错误: java .lang.NoClassDefFoundError:org / eclipse / jetty / continuation / ContinuationListener

是否可以创建一些简单的任务来完成jettyRun正在做的工作,但是使用jetty 8在最糟糕的情况下,我可以使用嵌入式版本的jetty与我正在建设的战争,但如果有任何问题,我会很乐意看到一些更简单的解决方案。 。

解决方案

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

  import org.eclipse.jetty.server.Server 
import org.eclipse.jetty。 webapp.WebAppContext
导入org.eclipse.jetty.server.bio.SocketConnector

对象JettyServer {

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

connector.setMaxIdleTime(1000 * 60 * 60)
连接器。 setPort(8080)

context.setServer(服务器)
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]
任务jettyRun(dependsOn:run)

一切正常:)


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...

解决方案

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 :)

这篇关于有没有简单的方法从gradle运行jetty 8(如jettyRun)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆