2011-11-25 59 views
8

我想用Gradle构建运行Jetty 7+,但看起来不幸似乎没有办法使用jettyRun做到这一点。所以,可能最简单的想法,以达到我想要的是使用自定义的目标:如何使用groovy/gradle与指定的战争运行jetty 7+?

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

倒霉的我刚开始gradle这个,我不知道常规要么,所以这对我来说很难创造适当的目标。我正在查看互联网,但我无法找到任何解决方案。 任何人都可以打我一些示例groovy代码,可以运行与码头现有的jar?

+0

的[可能重复有没有简单的方法来运行码头8从gradle这个(就像jettyRun)? ](http://stackoverflow.com/questions/8263168/is-there-any-easy-way-to-run-jetty-8-from-gradle-like-with-jettyrun) –

回答

14

好吧,我发现了如何使用直接从码头到仓库运行:

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 
} 
+0

我怎样才能创建一个使用Jetty 8的任务,并模仿jettyRunWar打包战争并将其部署到服务器? –

+0

你如何指定上下文路径?我试过--path contextPath。它不起作用。我可以在日志中看到这一点:o.e.j.w.WebAppContext {/,null} – singhspk

1

码头插件支持码头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 { 
     ... 
    } 
    } 
} 
+0

是的,我知道它有可能这样做,但我不喜欢这一行:“jettyRoot ='/ path/to/your/jetty/root'”。是否有可能添加jetty作为运行时依赖,并以某种方式获取gradle保存它的路径(获取后)? –

+0

您可以添加码头7作为一个依赖: 配置{ jetty7 } 依赖{ jetty7 “org.mortbay.jetty:码头:+” } ext.jettyRoot = configurations.jetty7 –

3

这是一个使用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") 
} 
+0

我没有看到任何IP地址在这里给出。我的主要目标是通过同一地区的其他设备连接我的网络服务。 – masiboo