天道酬勤,学无止境

How to run Jetty with Gradle

I have a Gradle project, and I'm trying to run it with it Jetty. My build.gradle file looks like following.

build.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'

[jettyRun, jettyRunWar]*.httpPort = 8080
[jettyRun, jettyRunWar]*.contextPath = ''
[jettyRun, jettyRunWar]*.daemon = true
[jettyRun, jettyRunWar, jettyStop]*.stopPort = 8081
[jettyRun, jettyRunWar, jettyStop]*.stopKey = 'stop'

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets {
    test {
        java {
            srcDirs = ['src/test/java']
        }
    }
}

dependencies {
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.14'
    compile 'com.google.guava:guava:14.0.1'
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    testCompile 'org.mockito:mockito-all:1.10.19'
    testCompile 'org.eclipse.jetty:jetty-server:9.4.7.v20170914'
    testCompile 'org.eclipse.jetty:jetty-webapp:9.4.7.v20170914'
}

I'm trying to run this project from the command line, and the commands I'm using are:

  1. ./gradlew which should build the project, and outputs the following:

    The Jetty plugin has been deprecated and is scheduled to be removed in Gradle 4.0. Consider using the Gretty (https://github.com/akhikhl/gretty) plugin instead. at build_6xw4u3prr68h02k136x2vqowd.run(/myproject/build.gradle:3) :help

    Welcome to Gradle 3.2.1.

  2. gradle jettyRun which failed with the statement Plugin with id 'jetty' not found.

So the question is, how do I run such a project? Note that I didn't write this project, I just need to run it on my local machine.

评论

I am no expert in Gradle, just a beginner, but i think I found something that can help you. I was also reading about using jetty with gradle, since I used it frequently with Maven.

Turns out, Jetty as a plugin is no longer supported as you can find here: https://docs.gradle.org/current/userguide/jetty_plugin.html

Instead, you are supposed to use gretty for the same end: https://plugins.gradle.org/plugin/org.gretty

Hope this was helpful.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Gradle:使用 Jetty 运行多个 webapp(Gradle: Run multiple webapps with Jetty)
    问题
  • How to run jetty 7+ with specified war with groovy/gradle?
    I want to run Jetty 7+ with gradle build, but unlucky looks like there is no way to do this with jettyRun. So probably simplest idea to achieve what I want would be to use custom target: task runJetty << { def server = new Server() // more code here server.start() server.join() } Unlucky I just started with gradle and I don't know groovy either, so it's hard for me to create proper target. I was looking over the internet but I wasn't able to find any solution. Can anyone hit me with some sample groovy code which can run existing jar with jetty?
  • 有没有什么简单的方法可以从 gradle 运行 jetty 8(比如使用 jettyRun)?(Is there any easy way to run jetty 8 from gradle (like with jettyRun)?)
    问题 不幸的是,我需要jetty 8 才能与spray/akka(它是scala 项目)一起正常工作。 对于 jettyRun 使用的旧版本,我收到如下错误: java.lang.NoClassDefFoundError: org/eclipse/jetty/continuation/ContinuationListener 是否可以创建一些简单的任务来完成 jettyRun 正在做但使用 jetty 8 的工作? 在最坏的情况下,我可以将码头的嵌入式版本与我正在构建的战争一起使用,但我很乐意看到一些更简单的解决方案,如果有的话...... 回答1 Pitor,你为什么不从这里添加你的优秀答案? 我在下面对其进行了修改,以使用 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
  • Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits & Gradle error: Task 'null' not found in root project
    Jenkins 2.176.4-3 rolling Gradle 4.3.1 Issue area: Parallel run of a given single Gradle task (or it could be any simple action) and especially when running concurrent runs of Jenkinsfile based pipelines All the sudden I got this error in Jenkins log page, never seen this error before (found no stackoverflow posts either for this error in Jenkins). Error: java.lang.IllegalArgumentException: Last unit does not have enough valid bits For some reason the previous build failed and automatically took me to Jenkins logs page showing Jenkins angry fire face: Re-ran just one run of Jenkinsfile
  • Proper way to install/run a gradle plugin from github (specifically the arquilian plugin)?
    I would like to use the arquillian plugin here to run jetty 8+: https://github.com/aslakknutsen/arquillian-gradle-plugin If I put "apply plugin: 'arquillian'" in my gradle script, it does not find it. So I must have to install it somehow. I look for info on this, but did not find. Would you have a pointer on how to do that? I am using gradle 1.6 on windows. Update after answer by @raeffs: I updated the gradle script with it and the build is successfull, but I don't see my war started after an arquillianRunJetty (port 8080 is not even listening). Then I tried to add what is indicated on the
  • 从github(特别是arquilian插件)安装/运行gradle插件的正确方法?(Proper way to install/run a gradle plugin from github (specifically the arquilian plugin)?)
    问题 我想在这里使用 arquillian 插件来运行 jetty 8+: https://github.com/aslakknutsen/arquillian-gradle-plugin 如果我将“应用插件:'arquillian'”放在我的 gradle 脚本中,它不会找到它。 所以我必须以某种方式安装它。 我正在寻找这方面的信息,但没有找到。 你有关于如何做到这一点的指针吗? 我在 Windows 上使用 gradle 1.6。 @raeffs 回答后更新:我用它更新了 gradle 脚本并且构建成功,但我没有看到我的战争在 arquillianRunJetty 之后开始(端口 8080 甚至没有监听)。 然后我尝试添加github页面上指示的内容: arquillian { debug = true deployable = file('my/path/arbitraryWebApp.war') containers { jetty { version = '8' type = 'embedded' config = ['bindHttpPort': 8080, 'bindAddress': '127.0.0.1', 'jettyPlus': false] dependencies { adapter 'org.jboss.arquillian.container
  • 如何在gradle中导出可执行jar,并且该jar可以运行,因为它包含参考库(how to export a executable jar in gradle, and this jar can run as it include reference libraries)
    问题 如何在gradle中导出可执行jar,并且该jar可以运行,因为它包含参考库。 build.gradle apply plugin: 'java' manifest.mainAttributes("Main-Class" : "com.botwave.analysis.LogAnalyzer") repositories { mavenCentral() } dependencies { compile ( 'commons-codec:commons-codec:1.6', 'commons-logging:commons-logging:1.1.1', 'org.apache.httpcomponents:httpclient:4.2.1', 'org.apache.httpcomponents:httpclient:4.2.1', 'org.apache.httpcomponents:httpcore:4.2.1', 'org.apache.httpcomponents:httpmime:4.2.1', 'ch.qos.logback:logback-classic:1.0.6', 'ch.qos.logback:logback-core:1.0.6', 'org.slf4j:slf4j-api:1.6.0', 'junit:junit:4.+' ) } 在我运行之后
  • 错误:(2, 0) 未找到 ID 为“jetty”的插件(Error:(2, 0) Plugin with id 'jetty' not found)
    问题 昨天我将 Android Studio 升级到 3.0 版,但我正在使用 LibGdx,升级后我无法构建我的项目。 当我尝试构建时,它给了我一个错误: 错误:(2, 0) 未找到 ID 为“jetty”的插件 我应该如何解决这个问题? 回答1 当前使用已弃用的jetty plugin html 模块,该jetty plugin已在 Gradle 4.1 版本中删除。 使用Gradle-4.1和android-gradle-plugin:3.0.0 Android Studio 3.0 LibGDX 尚不支持 Gradle 4.1,同样存在一个问题,现已针对 Gradle 4.6 升级 如果您还想使用 Android Studio 3.0 将 Gradle 从 4.1 降级到 3.3 在您的项目中找到 gradle 文件夹,打开gradle-wrapper.properties并将 distributionUrl 更改为 3.3 distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 将 Android-gradle-plugin 从 3.0.0 降级到 2.3.3 打开根build.gradle文件并找到工件并更改版本classpath 'com.android.tools
  • How to enable hot swapping in debug mode with gradle and jetty?
    I'm using jettyRun for running my simple spring application. I wanted to enable hot swapping with Intellij debuger, but looks like jetty doesn't catch the changes. On http://docs.codehaus.org/display/GRADLE/Gradle+Jetty+Plugin I seen that it should work with: jettyRun.scanIntervalSeconds=1 On the other hand, there is some inconsistency. On the gradle homepage this parameter is not listed: http://www.gradle.org/jetty_plugin. Anyway, is there any way to enable this on gradle?
  • How to run Jetty via Gradle in Debug Mode
    Does anyone know how to configure the jetty gradle plugin to run in debug mode so that I can attach a remote debugger? I've tried setting the gradle and java opts to: -Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n ...but it doesn't seem to work. I'm able to get my own jetty installation working fine, just not via gradle (jettyRun or jettyRunWar). Regards.
  • Gradle 嵌入式码头插件不会自动停止(Gradle embedded jetty plugin is not stopping automatically)
    问题 我可以使用 gradle jettyRunWar 命令运行嵌入式码头。 但是,它不会在程序终止时自动停止。 在stackoverflow和其他论坛上搜索解决方案后,我尝试了以下两个代码。 但没有一个有效。 1)build.gradle apply plugin: 'jetty' task runJetty() { jettyStop.stopPort = 8090 dependsOn jettyRunWar finalizedBy jettyStop } 2)build.gradle apply plugin: 'jetty' task runJetty() { doFirst { jettyRunWar.stopPort = 8090 jettyRunWar.stopKey = 'stopKey' jettyRunWar.daemon = true tasks.jettyRunWar.execute() } doLast { jettyStop.stopPort = 8090 jettyStop.stopKey = 'stopKey' tasks.jettyStop.execute() } } 在这两种情况下,在运行 runJetty 任务时,嵌入式 jetty 服务器启动但不会在程序终止时停止。 FWIW:我正在使用 Eclipse 外部工具配置来启动和终止 build
  • 创建名为“springSecurityFilterChain”的 bean 时出错(Error creating bean with name 'springSecurityFilterChain')
    问题 我一直在关注 Spring Security Reference,我只添加了这些类: @Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin().loginPage("/login") .permitAll() .and() .logout() .permitAll(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER").and() .withUser("user").password("password").roles(
  • 在 Gradle 中使用 jettyRun 将环境变量发送到码头(Sending an environment variable to jetty using jettyRun in Gradle)
    问题
  • 在 Google App Engine 上运行的 Spring Boot Web 应用程序 - 抛出码头异常(Spring Boot web application running on Google App Engine - throws jetty exception)
    问题 当我执行gradlew appengineRun ,我始终得到: Starting a Gradle Daemon (subsequent builds will be faster) Mar 26, 2018 5:47:48 PM java.util.prefs.WindowsPreferences <init> WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5. 2018-03-26 17:47:51.665:INFO::main: Logging initialized @3872ms 2018-03-26 17:47:53.727:INFO:oejs.Server:main: jetty-9.3.18.v20170406 2018-03-26 17:48:01.040:WARN:oeja.ClassInheritanceHandler:qtp99347477-18: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.get
  • Spring Boot web application running on Google App Engine - throws jetty exception
    When I execute gradlew appengineRun, I consistently get: Starting a Gradle Daemon (subsequent builds will be faster) Mar 26, 2018 5:47:48 PM java.util.prefs.WindowsPreferences <init> WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5. 2018-03-26 17:47:51.665:INFO::main: Logging initialized @3872ms 2018-03-26 17:47:53.727:INFO:oejs.Server:main: jetty-9.3.18.v20170406 2018-03-26 17:48:01.040:WARN:oeja.ClassInheritanceHandler:qtp99347477-18: java.lang.NullPointerException at java.util.concurrent
  • 如何使用Gradle配置硒测试?(How to configure selenium tests with gradle?)
    问题 我想在jboss上使用gradle运行硒测试,并且能够进行所需的配置,并且希望与社区共享。 回答1 我在我的Github帐户上做了一个完整的例子。 我的依赖项,仅使用mavenCentral存储库是: dependencies { compile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+' compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+' compile group: 'commons-io', name: 'commons-io', version: '1.3.+' compile group: 'junit', name: 'junit', version: '4.+' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+' compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.+' } 我将JBoss7作为服务运行(在Windows上),而不是尝试直接从Gradle中执行它。 我编写了一个脚本来注册服务(如果您想使用它)。 然后
  • Is there any easy way to run jetty 8 from gradle (like with jettyRun)?
    Unlucky I need jetty 8 to work properly with spray/akka (it's scala project). With older version used by jettyRun I'm getting error like: java.lang.NoClassDefFoundError: org/eclipse/jetty/continuation/ContinuationListener Is it possible to create some simple task to do the job which jettyRun is doing but with jetty 8? In worst case I can use embedded version of jetty with war which I'm building, but I would be happy to see some simpler solution if there is any...
  • 将jetty插件替换为gretty插件gradle时出错(Error while replacing jetty plugin to gretty plugin gradle)
    问题
  • Jetty 配置:MySQL JNDI 的问题(Jetty configuration: problems with MySQL JNDI)
    问题 嵌入的 Jetty 有一个用于配置的 jetty.xml。 这个配置有一个mysql jndi-connection。 当我用 gradle 运行 jetty 时,它抛出一个异常: Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86) at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:364) at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:754) at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1125) at org.eclipse.jetty.xml.XmlConfiguration
  • Gradle embedded jetty plugin is not stopping automatically
    I am able to run embedded jetty with gradle jettyRunWar command. However, it is not automatically stopped on program termination. I tried below two code after searching the solution on stackoverflow and other forums. But none works. 1) build.gradle apply plugin: 'jetty' task runJetty() { jettyStop.stopPort = 8090 dependsOn jettyRunWar finalizedBy jettyStop } 2) build.gradle apply plugin: 'jetty' task runJetty() { doFirst { jettyRunWar.stopPort = 8090 jettyRunWar.stopKey = 'stopKey' jettyRunWar.daemon = true tasks.jettyRunWar.execute() } doLast { jettyStop.stopPort = 8090 jettyStop.stopKey =