Gretty / Jetty无法使用Java 11,Jetty 9.4.14,gretty加载WebAppContext

时间:2019-06-28 04:05:00

标签: java gradle jetty resteasy gretty

我尝试使用:

使用以下子项目build.gradle:

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 clean build 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 个答案:

答案 0 :(得分:0)

我在主 build.gradle buildscript 方法中使用Getty libs依赖项:

buildscript {
  repositories {
        maven {
            url mirrorRepoUrl
        }
   }

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

这应该只为Gradle CL添加Gretty库,如果您使用的是grettyRunnerJetty94,则该库在服务器运行时可用,但未包含在WAR的构建中(这正是我想要的,所以我想谢谢)。