java - NoSuchMethodError : org. apache.commons.codec.binary.Base64.(I)V 在 org.apache.http.impl.auth.BasicScheme.(BasicScheme.java:65)

标签 java post glassfish httpclient apache-commons

即使我没有使用 Base64,也会发生这种情况。

我确实在 Glassfish 中的域的 lib 目录中引用了 commons-codec-1.9,并且在 httpclient-4.3.4 和 lib 目录中也引用了导致错误的代码。

    try {
        Authenticator.setDefault(new Authenticator()
        {
            @Override
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication("myusername", "mypassword".toCharArray());
            }
        });

        String xmlRequestString = formatXMLRequest((Exception) exception);

        HttpClient client = HttpClientBuilder.create().build();

        HttpPost post = new HttpPost("http://mysite.org/post.xml");

        StringEntity entity = new StringEntity(xmlRequestString);
        entity.setContentType("text/xml");

        post.setEntity(entity);

        client.execute(post); // <--- HERE is where the error is thrown
    } catch (Exception ex) {
        Logger.getLogger(LogManagerBean.class.getName()).log(Level.SEVERE, null, ex);
    }

有什么想法吗?

最佳答案

这是一个二进制兼容性问题,是由于 Web 应用程序的有效类路径中的库不兼容而导致的。具体来说,包含 BasicScheme 类的 JAR 文件与包含 Base64 类的 JAR 文件不兼容。前者包含对类加载器找到的后者版本中不存在的方法的调用。

This is occurring even though I'm not using Base64.

是的。但是 BasicScheme 类 >> 是<<,并且有东西使用该类。

<小时/>

签名org.apache.commons.codec.binary.Base64.(I)V指的是采用int参数的构造函数。根据 GrepCode 的说法,自 1.4 版以来的所有版本的 Apache Commons Codec 都有这个构造函数。但1.3版本没有。因此,请在您的应用程序服务器中查找“commons-codec”JAR 文件的旧副本。

请注意,如果 Web 应用(或其他应用程序)的类路径中有多个版本的库,则类路径中较早的 JAR 文件中的版本获胜

关于java - NoSuchMethodError : org. apache.commons.codec.binary.Base64.(I)V 在 org.apache.http.impl.auth.BasicScheme.(BasicScheme.java:65),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24835796/

相关文章:

php - 如何使用 AJAX 将信息发送到 PHP 脚本?

java - 在 netbeans 8.2 中添加 Glassfish Server 5.0

java - 从 ear/lib/jar 中的 ear/war 获取类返回 ClassNotFoundException

java - Glassfish 上的纯 Java 应用程序?

java - Spring Boot父启动器依赖覆盖

java - 如何使用java并行流代替executorThreadsPool?

java - 安装了JDK但没有javap?

php - 使用PHP在Twitter上发布时加剧问题

java - 尝试将数据存储区数据保存在 csv 文件中

javascript - 使用 Google 脚本的 MWS 发布请求