【问题标题】: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
【解决方案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)
一切正常 :)