繁体   English   中英

如何用groovy / gradle指定战争运行码头7+?

[英]How to run jetty 7+ with specified war with groovy/gradle?

我想用gradle构建运行Jetty 7+,但不幸的是看起来没有办法用jettyRun来做这件事。 因此,实现我想要的最简单的想法是使用自定义目标:

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

不幸的是我刚从gradle开始,我也不知道groovy,所以我很难创建合适的目标。 我正在寻找互联网,但我找不到任何解决方案。 任何人都可以用一些样本groovy代码打我,可以用jetty运行现有的jar吗?

好的,我发现如何直接从存储库使用jetty运行它:

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
}

这是一个使用jetty ant任务的工作版本。 这最终使我能够使用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")
}

有一个jetty-eclipse-plugin允许你运行更新版本的jetty https://github.com/Khoulaiz/gradle-jetty-eclipse-plugin

jetty插件目前支持jetty 6.1.25

你可以使用这样的东西:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM