【问题标题】:Is there any easy way to run jetty 8 from gradle (like with jettyRun)?有什么简单的方法可以从 gradle 运行 jetty 8(比如使用 jettyRun)?
【发布时间】:2012-01-05 23:36:05
【问题描述】:

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

在最坏的情况下,我可以将嵌入式版本的码头与我正在构建的战争一起使用,但如果有的话,我很乐意看到一些更简单的解决方案......

【问题讨论】:

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


    【解决方案1】:

    Pitor,您为什么最后没有添加来自here 的出色答案?

    我在下面对其进行了调整,使用 Jetty 版本 9,依赖于 war 任务,并使用与码头插件相同的任务名称(即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
    

    【讨论】:

      【解决方案2】:

      我认为答案有点晚了 :) 但我会将其发布给其他会在谷歌上搜索相同内容的人。

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

      【讨论】:

        【解决方案3】:

        由于我无法在 gradle 构建级别找到好的解决方案,我决定使用嵌入式码头。这是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)
        

        一切正常 :)

        【讨论】:

          猜你喜欢
          • 2015-05-16
          • 2016-08-03
          • 2019-08-03
          • 2013-09-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-16
          • 1970-01-01
          相关资源
          最近更新 更多