简体   繁体   English

java.lang.ClassNotFoundException:org.apache.commons.codec.binary.Base64

[英]java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64

Here I'm passing three parameters to this sign method.在这里,我将三个参数传递给这个 sign 方法。 In this line在这一行

signature = new String(Base64.encodeBase64(mac.doFinal(data.getBytes(UTF_8_Encoding))));签名=新字符串(Base64.encodeBase64(mac.doFinal(data.getBytes(UTF_8_Encoding))));

I'm getting error:我收到错误:

SEVERE: Servlet.service() for servlet [com.asp.amz.amzServlet] in context with path [/amazon] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64严重:servlet [com.asp.amz.amzServlet] 在路径 [/amazon] 上下文中的 Servlet.service() 引发异常 [Servlet 执行引发异常],根本原因 java.lang.ClassNotFoundException:org.apache.com codec.binary.Base64

String Key = "z/0qfiE+ScjxHy2gSwmHqP0rZ6fT9zhVgsNt";
String signatureMethod = "HmacSHA256";
String data = "sandbox.amazon.com/cobranded-ui/actions/start?callerKey=AKIAJZOKEUCXF7RKSCNA&callerReference=callerReferenceSingleUse&currencyCode=USD&paymentReason=HarryPotter%201-5%20DVD%20set&pipelineName=SingleUse&returnURL=http%3A%2F%2Flocalhost%3A8888%2Famazon&signatureMethod=HmacSHA256&signatureVersion=2&transactionAmount=5&version=2009-01-09";

    private static String sign(String data, String key, String signatureMethod) throws SignatureException
    {
        System.out.println(" In sign block ");
        String signature = "";
        try {
            System.out.println(" In sign Try block ");
            Mac mac = Mac.getInstance(signatureMethod);
            mac.init(new SecretKeySpec(key.getBytes(), signatureMethod));
            signature = new String(Base64.encodeBase64(mac.doFinal(data.getBytes(UTF_8_Encoding))));
            System.out.println(" In sign Try block ");
        } catch (Exception e) {
            System.out.println(" In sign catch block ");
            throw new SignatureException("Failed to generate signature: " + e.getMessage(), e);         
        }
        System.out.println(" End sign block " + signature);
        return signature;
    }

just add commons-codec.jar into your classpath只需将commons-codec.jar添加到您的类路径中

Get commons-codec.jar from Apache HTTP ComponentsApache HTTP 组件获取commons-codec.jar

There could be Two Reason for that:可能有两个原因:

First Reason: 1. The jar itself is not added in the pom.xml.第一个原因: 1. jar本身没有添加到pom.xml中。 In that case, add the dependency version in the pom.xml which has the class for which you are getting error在这种情况下,在 pom.xml 中添加依赖版本,其中包含您遇到错误的 class

Second Reason: When there are multiple jars added in the project and the jar version which is near to the project doesn't have that class.第二个原因:当项目中添加了多个jars,而项目附近的jar版本没有那个class。 You can check the nearest jar in your project below command您可以在下面的项目中检查最近的 jar 命令

mvn dependency:tree -Dverbose -Dincludes=jar-name-casuing-conflict

在此处输入图像描述

Once you identify the Jar version which has that class.一旦您确定了具有 class 的 Jar 版本。 You can resolve by adding that jar directly in your project pom.xml您可以通过在项目 pom.xml 中直接添加 jar 来解决

or You can exclude the jar that is nearer to your project which doesn't has that class and can point to another jar in the project.或者您可以排除离您的项目更近的 jar 没有该 class 并且可以指向项目中的另一个 jar。

Example: it will exclude the jar in the project "org.cassandraunit" then it will see the immediate next jar that's close to the project will be used in your project示例:它将排除项目“org.cassandraunit”中的 jar 然后它会立即看到下一个靠近项目的 jar 将在您的项目中使用

   <dependency>
            <groupId>org.cassandraunit</groupId>
            <artifactId>cassandra-unit</artifactId>
            <version>3.1.3.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

when you have error you can get all jar in picture,then your project will be ok.当你有错误时,你可以得到图片中的所有 jar,那么你的项目就可以了。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试创建CommonsHttpOAuthConsumer时java.lang.ClassNotFoundException:org.apache.commons.codec.binary.Base64 - java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 when trying to create CommonsHttpOAuthConsumer C#中的org.apache.commons.codec.binary.Base64 - org.apache.commons.codec.binary.Base64 in C# 如何使用org.apache.commons.codec.binary.base64对Java对象进行Base64编码? - How to Base64 encode a Java object using org.apache.commons.codec.binary.base64? Java-org.apache.commons.codec.binary.Base64消除换行符 - Java - org.apache.commons.codec.binary.Base64 eliminate new line characters 如何将sun.misc.BASE64Encoder转换为org.apache.commons.codec.binary.Base64 - How to convert sun.misc.BASE64Encoder to org.apache.commons.codec.binary.Base64 如何用org.apache.commons.codec.binary.Base64替换android.util.Base64? - How to replace android.util.Base64 by org.apache.commons.codec.binary.Base64? java.lang.NoMethodError:org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString - java.lang.NoMethodError : org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString java.lang.NoSuchMethodError:org.apache.commons.codec.binary.Base64.encodeBase64String - java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String java.lang.NoClassDefFoundError:org / apache / commons / codec / binary / Base64 - java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64 Selenium SouceLabs-java.lang.NoClassDefFoundError:org / apache / commons / codec / binary / Base64 - Selenium SouceLabs - java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM