org/apache/http/util/Args (java.lang.NoClassDefFoundError). Message payload is of type: String

╄→гoц情女王★ 提交于 2020-01-05 14:12:43

问题


My mule application is able to run with the following maven dependencies.

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.9.40</version>
    </dependency>

    <dependency> 
        <groupId>org.apache.httpcomponents</groupId> 
        <artifactId>httpcore</artifactId> 
        <version>4.4.1</version> 
    </dependency> 

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.4.1</version>
    </dependency>

It runs smoothly, however as soon as I send POST to it, it generates the "NoClassDefFoundError"


ERROR 2015-06-11 12:34:10,406 [[dynamodb-01].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : org/apache/http/util/Args (java.lang.NoClassDefFoundError). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. org.apache.http.util.Args (java.lang.ClassNotFoundException)
  java.net.URLClassLoader$1:366 (null)
2. org/apache/http/util/Args (java.lang.NoClassDefFoundError)
  org.apache.http.conn.scheme.Scheme:90 (null)
3. org/apache/http/util/Args (java.lang.NoClassDefFoundError). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassNotFoundException: org.apache.http.util.Args
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

回答1:


Your error indicates that your application in missing a class in jar httpcore.4.4.1 during runtime. Try giving a dependency scope of runtime for your libraries that you are importing.

Check the below url https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

<dependency> 
        <groupId>org.apache.httpcomponents</groupId> 
        <artifactId>httpcore</artifactId> 
        <version>4.4.1</version>
<scope>runtime</scope>
    </dependency> 

If the jar is also required for compilation and runtime, use the scope "provided".

<dependency> 
        <groupId>org.apache.httpcomponents</groupId> 
        <artifactId>httpcore</artifactId> 
        <version>4.4.1</version>
<scope>provided</scope>
    </dependency>

Please note that the default scope in maven (if nothing is specified) is compile, where in the library will be only used for compilation.



来源:https://stackoverflow.com/questions/30771696/org-apache-http-util-args-java-lang-noclassdeffounderror-message-payload-is-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!