当前位置: 首页 > 知识库问答 >
问题:

Gretty/Jetty无法使用java 11、Jetty 9.4.14和Gretty加载WebAppContext

周和安
2023-03-14

我尝试使用:

  • Java11
  • RestEasy 4.1.0最终版
  • 码头9.4.19. v20190610
  • gretty-gradle-plugin来自https://raw.github.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty.plugin

使用下面的子项目构建。格雷德尔:

apply plugin: 'war'
apply from: 'https://raw.github.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty.plugin'

gretty {
    jacocoEnabled false
}

war{
    archiveName project.name+".war"
}

gretty {
  servletContainer = 'jetty9.4'
  httpPort = 8081
}

dependencies {
    [...]
    grettyRunnerJetty94 group: 'org.eclipse.jetty', name: 'jetty-runner', version: '9.4.19.v20190610'
}

但是,当我试图运行我的服务器使用:gradlew清洁构建runApp我得到以下异常:

14:53:16 WARN  org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher defines neither @WebServlet.value nor @WebServlet.urlPatterns
14:53:16 WARN  Failed startup of context o.a.g.JettyWebAppContext@26a94fa5{PEPS,/peps-api-server,file:///home/isinc/devel/enercal/peps-api/server/build/inplaceWebapp/,UNAVAILABLE}
java.lang.IncompatibleClassChangeError: class org.jboss.resteasy.specimpl.LinkBuilderImpl can not implement javax.ws.rs.core.Link$Builder, because it is not an interface (javax.ws.rs.core.Link$Builder is in unnamed module of loader org.akhikhl.gretty.FilteringClassLoader @20921b9b)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) ~[na:na]
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[na:na]
        at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550) ~[na:na]
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458) ~[na:na]
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452) ~[na:na]
        at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451) ~[na:na]
        at org.eclipse.jetty.webapp.WebAppClassLoader.foundClass(WebAppClassLoader.java:670) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.webapp.WebAppClassLoader.loadAsResource(WebAppClassLoader.java:639) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:545) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.akhikhl.gretty.FilteringClassLoader.loadClass(FilteringClassLoader.java:72) ~[gretty-runner-jetty94-2.3.0.jar:na]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
        at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:87) ~[na:na]
        at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28) ~[na:na]
        at org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener.contextInitialized(GuiceResteasyBootstrapServletContextListener.java:37) ~[na:na]
        at nc.enercal.gcf.peps.ServiceGuiceServletConfig.contextInitialized(ServiceGuiceServletConfig.java:30) ~[na:na]
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:959) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:553) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:924) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:365) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:854) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:278) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.akhikhl.gretty.JettyWebAppContext.doStart(JettyWebAppContext.groovy:44) ~[gretty-runner-jetty94-2.3.0.jar:na]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:167) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:119) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:167) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.Server.start(Server.java:418) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:110) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.server.Server.doStart(Server.java:382) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-runner-9.4.19.v20190610.jar:9.4.19.v20190610]
        at org.eclipse.jetty.util.component.LifeCycle$start$0.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) ~[groovy-2.4.15.jar:2.4.15]
        at org.akhikhl.gretty.JettyServerManager.startServer(JettyServerManager.groovy:48) ~[gretty-runner-jetty-2.3.0.jar:na]
        at org.akhikhl.gretty.ServerManager$startServer$0.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) ~[groovy-2.4.15.jar:2.4.15]
        at org.akhikhl.gretty.Runner.run(Runner.groovy:121) ~[gretty-runner-2.3.0.jar:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-2.4.15.jar:2.4.15]
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) ~[groovy-2.4.15.jar:2.4.15]
        at org.akhikhl.gretty.Runner.main(Runner.groovy:48) ~[gretty-runner-2.3.0.jar:na]
14:53:16 INFO  Jetty 9.4.14.v20181114 started and listening on port 8081


服务器没有加载我的Servlet...

有人遇到过这个问题并找到了解决方案吗?

共有1个答案

陆琦
2023-03-14

我在主build.gradle的构建脚本方法中使用Getty libs依赖:

buildscript {
  repositories {
        maven {
            url mirrorRepoUrl
        }
   }

  dependencies {
    classpath 'org.gretty:gretty:+'
  }
}

这应该只为Gradle CL添加Gretty libs,如果您使用的是grettyRunnerJetty94,该lib在服务器运行时可用,但它不包括在build for WAR中(这正是我想要的,所以我要感谢您)。

 类似资料:
  • Gretty 是一个简单的 Web 框架,用于构建 Web 服务端和客户端,基于 Netty 开发,支持 NIO 风格的 HTTP 服务器,异步 HTTP 客户端,支持 WebSocket 的服务器和客户端。

  • 我没有使用Gradle的经验,我对任务和插件的工作方式略有了解,但不是很深入。 我的问题是关于Jetty插件的,它现在已经不推荐使用了,Gradle建议我使用Gretty插件。 我已经把它放进了我的代码中,但是,当然,现在我需要将Jetty任务改为Gretty任务,这就是我现在的问题。 提前谢谢!!

  • 如何配置Jetty9以使用Gretty侦听多个端口。我只想配置Jetty监听多个端口。我不想要多个实例或多个webapp,只是一个Jetty,一个webapp,但监听2个或更多的端口。 谢谢!

  • 可以在Docker Gradle容器中运行Gretty项目吗? 通常情况下,Gretty任务< code>tomcatRun会启动Tomcat应用程序服务器,您可以在http://localhost:8080/app-name上浏览应用程序。使用Docker Gradle image,任务可以成功启动,但之后容器会立即终止。 复制问题的步骤: < li >安装Docker。 <李>克隆https:

  • 我使用的Gretty示例来自:https://github.com/gretty-gradle-plugin/gretty-sample在主build.gradle我只修改了存储库URL(使用镜像回购由于代理): 建造。格雷德尔: 您可以看到端口被指定为: httpPort=8011 在子项目部分。当我运行Gradle时 格雷德卢:农场跑步 它报告: 因此,jetty仍在尝试使用默认端口8080。

  • 我正在尝试用gradle gretty插件(gradle版本3.4)构建一个JavaServlet。我依赖于另一个项目数据库提供程序: 1.0-SNAPSHOT(包括与数据库的连接和一些Spring定义...)。当我运行任务“gradle war”时,. war-file与WEB-INF/lib中的所有依赖关系都已正确构建。但是当我尝试从“gradle appstart”开始时,我有以下问题: 错