[英]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.