JAX-RS: "RESTEASY002005: Failed executing GET org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure

huangapple go评论77阅读模式
英文:

JAX-RS: "RESTEASY002005: Failed executing GET org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure

问题

I have created a simple service that enables me to listen to incoming REST requests and then perform a task and return the output of the task back to the caller as a custom object (MyObject).

This service runs perfectly fine while I execute it from IntelliJ [I am assuming the JAX-RS jar are being loaded from IntelliJ's internal repository] but fails when I execute the JAR from the command line. The exception is as follows:

[ERROR] RESTEASY002005: Failed executing GET /myapp/getVal
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.myproject.model.MyObject of media type: application/json
    at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$2(ServerResponseWriter.java:104) ~[myapp-jar-with-dependencies.jar:na]
    ...

My code snippets are as follows:

Parent pom:

<!-- Your parent pom content -->

My child pom:

<!-- Your child pom content -->

My REST API code:

@Path("/myapp")
@Singleton
public class MyResource {

    @GET
    @Path("/getVal")
    @Produces(MediaType.APPLICATION_JSON)
    public MyObject getVal(@QueryParam("id") @NonNull String id) throws Exception {
        try {
            return getMyObjData(id);
        } catch(IllegalArgumentException e) {
            throw new Exception(e.getMessage());
        }
    }
}

It seems that the issue might be related to missing dependencies in the JAR when executing it from the command line. You have mentioned updating the parent and child poms, but those updates are not included in the text you provided.

Please ensure that your JAR includes all the necessary dependencies and libraries when you build it, especially the JAX-RS related dependencies that seem to be causing the issue.

英文:

I have created a simple service that enables me to listen to incoming REST requests and then perform a task and return the output of the task back to the caller as a custom object (MyObject).

This service runs perfectly fine while I execute it from IntelliJ [i am assuming the jaxrs jar are being loaded from InteliJ's internal repository] but fails when i execute the jar from command line. The exception is as follows:

[ERROR] RESTEASY002005: Failed executing GET /myapp/getVal
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.myproject.model.MyObject of media type: application/json
    at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$2(ServerResponseWriter.java:104) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.interception.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:398) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:205) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:82) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:56) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:528) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:459) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:355) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:227) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) ~[myapp-jar-with-dependencies.jar:na]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) ~[myapp-jar-with-dependencies.jar:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.Server.handle(Server.java:502) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765) ~[myapp-jar-with-dependencies.jar:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683) ~[myapp-jar-with-dependencies.jar:na]

My code snippets are as follows:

parent pom:

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.myproject&lt;/groupId&gt;
&lt;artifactId&gt;myapp&lt;/artifactId&gt;
&lt;packaging&gt;pom&lt;/packaging&gt;
&lt;version&gt;1.4-SNAPSHOT&lt;/version&gt;
&lt;name&gt;My Application&lt;/name&gt;
&lt;description&gt;My Application&lt;/description&gt;
&lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
&lt;maven-compiler-plugin.version&gt;3.2&lt;/maven-compiler-plugin.version&gt;
&lt;maven-assembly-plugin.version&gt;2.4&lt;/maven-assembly-plugin.version&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;sonar.jacoco.reportPath&gt;${coverage.reports.dir}/jacoco-unit.exec&lt;/sonar.jacoco.reportPath&gt;
&lt;sonar.jacoco.itReportPath&gt;${coverage.reports.dir}/jacoco-it.exec&lt;/sonar.jacoco.itReportPath&gt;
&lt;sonar.jacoco.agent.jar&gt;${basedir}/target/jacoco-jars/jacocoagent.jar&lt;/sonar.jacoco.agent.jar&gt;
&lt;jacoco.reports.unit.dir&gt;${basedir}/target/jacoco-reports/unit&lt;/jacoco.reports.unit.dir&gt;
&lt;jacoco.reports.it.dir&gt;${basedir}/target/jacoco-reports/it&lt;/jacoco.reports.it.dir&gt;
&lt;coverage.reports.dir&gt;${basedir}/target/coverage-reports&lt;/coverage.reports.dir&gt;
&lt;sonar.dynamic&gt;reuseReports&lt;/sonar.dynamic&gt;
&lt;guice.version&gt;4.1.0&lt;/guice.version&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
&lt;jetty.version&gt;9.4.14.v20181114&lt;/jetty.version&gt;
&lt;resteasy.version&gt;3.6.2.Final&lt;/resteasy.version&gt;
&lt;maven.build.timestamp.format&gt;yyyyMMdd&#39;T&#39;HHmm&lt;/maven.build.timestamp.format&gt;
&lt;/properties&gt;
&lt;scm&gt;
&lt;!-- My scm --&gt;
&lt;/scm&gt;
&lt;repositories&gt;
&lt;!-- My repositories --&gt;
&lt;/repositories&gt;
&lt;modules&gt;
&lt;module&gt;myChild&lt;/module&gt;
&lt;/modules&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
&lt;artifactId&gt;logback-core&lt;/artifactId&gt;
&lt;version&gt;1.1.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
&lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
&lt;version&gt;1.1.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;log4j-over-slf4j&lt;/artifactId&gt;
&lt;version&gt;1.7.7&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
&lt;version&gt;${jetty.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-guice&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jackson2-provider&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.google.inject.extensions&lt;/groupId&gt;
&lt;artifactId&gt;guice-multibindings&lt;/artifactId&gt;
&lt;version&gt;${guice.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
&lt;build&gt;
&lt;finalName&gt;myapp&lt;/finalName&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;2.3.2&lt;/version&gt;
&lt;configuration&gt;
&lt;source&gt;1.8&lt;/source&gt;
&lt;target&gt;1.8&lt;/target&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;descriptorRefs&gt;
&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
&lt;/descriptorRefs&gt;
&lt;archive&gt;
&lt;manifest&gt;
&lt;mainClass&gt;com.myproject.main.mainClass&lt;/mainClass&gt;
&lt;/manifest&gt;
&lt;/archive&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;make-assembly&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;single&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.3&lt;/version&gt;
&lt;configuration&gt;
&lt;localCheckout&gt;true&lt;/localCheckout&gt;
&lt;autoVersionSubmodules&gt;true&lt;/autoVersionSubmodules&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;version&gt;2.18.1&lt;/version&gt;
&lt;configuration&gt;
&lt;argLine&gt;-Dfile.encoding=${project.build.sourceEncoding} ${argLine}&lt;/argLine&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jacoco&lt;/groupId&gt;
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.8.3&lt;/version&gt;
&lt;configuration&gt;
&lt;destFile&gt;${basedir}/target/coverage-reports/jacoco-unit.exec&lt;/destFile&gt;
&lt;dataFile&gt;${basedir}/target/coverage-reports/jacoco-unit.exec&lt;/dataFile&gt;
&lt;append&gt;true&lt;/append&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;agent-for-ut&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;prepare-agent&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;jacoco-site&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;report&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

My child pom:

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;parent&gt;
&lt;groupId&gt;com.myproject&lt;/groupId&gt;
&lt;artifactId&gt;myapp&lt;/artifactId&gt;
&lt;version&gt;1.4-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.myproject.myapp&lt;/groupId&gt;
&lt;artifactId&gt;myChildApp&lt;/artifactId&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;name&gt;myChildApp&lt;/name&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-cli&lt;/groupId&gt;
&lt;artifactId&gt;commons-cli&lt;/artifactId&gt;
&lt;version&gt;1.3.1&lt;/version&gt;
&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-guice&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jackson2-provider&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
&lt;version&gt;5.2.5.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/project&gt;

My REST API code is a follows:


@Path(&quot;/myapp&quot;)
@Singleton
public class MyResource {
@GET
@Path(&quot;/getVal&quot;)
@Produces(MediaType.APPLICATION_JSON)
public MyObject getVal(@QueryParam(&quot;id&quot;) @NonNull String id) throws Exception {
try {
return getMyObjData(id);
} catch(IllegalArgumentException e) {
throw new Exception(e.getMessage());
}
}
}

I have gone through a couple of links with similar issues but none helped me. For example:

https://stackoverflow.com/questions/19089781/resteasy-could-not-find-messagebodywriter-for-response-object-of-type-java-uti

https://stackoverflow.com/questions/43833220/get-request-fails-with-jax-rs-could-not-find-messagebodywriter-for-response-obj

https://stackoverflow.com/questions/52807266/simple-example-using-resteasy-jaxrs-not-working

Based on my debugging with IntelliJ and by running the jar on command line, it appears to me that the jar I am trying to build does not have the dependency of jaxrs (if I am not mistaken) even though I have added them onto my pom. I therefore, am unsure how to proceed with this issue. Can someone help me out with this?

Update:

As per the comment I have updated my parent and child pom as below:

Parent pom

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.myproject&lt;/groupId&gt;
&lt;artifactId&gt;myapp&lt;/artifactId&gt;
&lt;packaging&gt;pom&lt;/packaging&gt;
&lt;version&gt;1.4-SNAPSHOT&lt;/version&gt;
&lt;name&gt;My Application&lt;/name&gt;
&lt;description&gt;My Application&lt;/description&gt;
&lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
&lt;maven-compiler-plugin.version&gt;3.2&lt;/maven-compiler-plugin.version&gt;
&lt;maven-assembly-plugin.version&gt;2.4&lt;/maven-assembly-plugin.version&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;sonar.jacoco.reportPath&gt;${coverage.reports.dir}/jacoco-unit.exec&lt;/sonar.jacoco.reportPath&gt;
&lt;sonar.jacoco.itReportPath&gt;${coverage.reports.dir}/jacoco-it.exec&lt;/sonar.jacoco.itReportPath&gt;
&lt;sonar.jacoco.agent.jar&gt;${basedir}/target/jacoco-jars/jacocoagent.jar&lt;/sonar.jacoco.agent.jar&gt;
&lt;jacoco.reports.unit.dir&gt;${basedir}/target/jacoco-reports/unit&lt;/jacoco.reports.unit.dir&gt;
&lt;jacoco.reports.it.dir&gt;${basedir}/target/jacoco-reports/it&lt;/jacoco.reports.it.dir&gt;
&lt;coverage.reports.dir&gt;${basedir}/target/coverage-reports&lt;/coverage.reports.dir&gt;
&lt;sonar.dynamic&gt;reuseReports&lt;/sonar.dynamic&gt;
&lt;guice.version&gt;4.1.0&lt;/guice.version&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
&lt;jetty.version&gt;9.4.14.v20181114&lt;/jetty.version&gt;
&lt;resteasy.version&gt;3.6.2.Final&lt;/resteasy.version&gt;
&lt;maven.build.timestamp.format&gt;yyyyMMdd&#39;T&#39;HHmm&lt;/maven.build.timestamp.format&gt;
&lt;/properties&gt;
&lt;scm&gt;
&lt;!-- My scm --&gt;
&lt;/scm&gt;
&lt;repositories&gt;
&lt;!-- My repositories --&gt;
&lt;/repositories&gt;
&lt;modules&gt;
&lt;module&gt;myChild&lt;/module&gt;
&lt;/modules&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
&lt;artifactId&gt;logback-core&lt;/artifactId&gt;
&lt;version&gt;1.1.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
&lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
&lt;version&gt;1.1.3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.slf4j&lt;/groupId&gt;
&lt;artifactId&gt;log4j-over-slf4j&lt;/artifactId&gt;
&lt;version&gt;1.7.7&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
&lt;version&gt;${jetty.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-guice&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jackson2-provider&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.google.inject.extensions&lt;/groupId&gt;
&lt;artifactId&gt;guice-multibindings&lt;/artifactId&gt;
&lt;version&gt;${guice.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;2.3.2&lt;/version&gt;
&lt;configuration&gt;
&lt;source&gt;1.8&lt;/source&gt;
&lt;target&gt;1.8&lt;/target&gt;
&lt;localCheckout&gt;true&lt;/localCheckout&gt;
&lt;autoVersionSubmodules&gt;true&lt;/autoVersionSubmodules&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.3&lt;/version&gt;
&lt;configuration&gt;
&lt;localCheckout&gt;true&lt;/localCheckout&gt;
&lt;autoVersionSubmodules&gt;true&lt;/autoVersionSubmodules&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jacoco&lt;/groupId&gt;
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.8.3&lt;/version&gt;
&lt;configuration&gt;
&lt;destFile&gt;${basedir}/target/coverage-reports/jacoco-unit.exec&lt;/destFile&gt;
&lt;dataFile&gt;${basedir}/target/coverage-reports/jacoco-unit.exec&lt;/dataFile&gt;
&lt;append&gt;true&lt;/append&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;agent-for-ut&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;prepare-agent&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;jacoco-site&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;report&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
&lt;version&gt;3.0.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;validate&lt;/id&gt;
&lt;phase&gt;validate&lt;/phase&gt;
&lt;configuration&gt;
&lt;configLocation&gt;google_checks.xml&lt;/configLocation&gt;
&lt;encoding&gt;UTF-8&lt;/encoding&gt;
&lt;consoleOutput&gt;true&lt;/consoleOutput&gt;
&lt;failsOnError&gt;true&lt;/failsOnError&gt;
&lt;linkXRef&gt;false&lt;/linkXRef&gt;
&lt;/configuration&gt;
&lt;goals&gt;
&lt;goal&gt;check&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;

Child pom:

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;parent&gt;
&lt;groupId&gt;com.myproject&lt;/groupId&gt;
&lt;artifactId&gt;myapp&lt;/artifactId&gt;
&lt;version&gt;1.4-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.myproject.myapp&lt;/groupId&gt;
&lt;artifactId&gt;myChildApp&lt;/artifactId&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;name&gt;myChildApp&lt;/name&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-cli&lt;/groupId&gt;
&lt;artifactId&gt;commons-cli&lt;/artifactId&gt;
&lt;version&gt;1.3.1&lt;/version&gt;
&lt;scope&gt;compile&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-guice&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-jackson2-provider&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
&lt;version&gt;5.2.5.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
&lt;version&gt;3.2.1&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;shade&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;filters&gt;
&lt;filter&gt;
&lt;artifact&gt;*:*&lt;/artifact&gt;
&lt;excludes&gt;
&lt;exclude&gt;META-INF/*.SF&lt;/exclude&gt;
&lt;exclude&gt;META-INF/*.DSA&lt;/exclude&gt;
&lt;exclude&gt;META-INF/*.RSA&lt;/exclude&gt;
&lt;/excludes&gt;
&lt;/filter&gt;
&lt;/filters&gt;
&lt;transformers&gt;
&lt;transformer implementation=&quot;org.apache.maven.plugins.shade.resource.ManifestResourceTransformer&quot;&gt;
&lt;mainClass&gt;com.myproject.main.mainClass&lt;/mainClass&gt;
&lt;/transformer&gt;
&lt;/transformers&gt;
&lt;createDependencyReducedPom&gt;false&lt;/createDependencyReducedPom&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

Even after the above set of changes, I still see the same error.

答案1

得分: 1

问题类似于这个涉及Jersey的问题,其中用于自动注册提供程序的服务文件被排除在使用maven-assembly-plugin构建的fat jar之外。解决方案 是使用maven-shade-plugin,它具有一个转换器,用于将所有服务文件的内容连接到一个文件中,以供单个uber jar 使用。

英文:

The problem is similar to this one with Jersey where the services files (used to autoregister providers) are excluded from the fat jar built with the maven-assembly-plugin. The solution is to use the maven-shade-plugin, which has a transformer to concatenate the contents of all the services files into one file for the one single uber jar.

答案2

得分: 0

经过几个小时的调试,我成功地找到了问题出在哪里。正如上面的pom文件所示,我正在使用Google Guice进行依赖注入(DI)。
在使用Guice时,我们需要绑定JacksonProvider,如下所示:

bind(JacksonJsonProvider.class)

之所以在我的集成开发环境(IDE)中可以正常工作,是因为IDE从其本地仓库(类路径)中加载了必要的依赖。

这解决了我的问题。

英文:

After a couple of hours of debugging, I was able to find where the issue was. As can be seen in the pom files above, I am making use of Google Guice for DI.
While using Guice, we need to bind JacksonProvider as shown below:

bind(JacksonJsonProvider.class)

The reason why it was working for me on my IDE was because the IDE was loading the necessary dependency from its local repository (classpath).

This fixed the issue for me.

huangapple
  • 本文由 发表于 2020年9月2日 21:38:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63706782.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定