java.lang.NoSuchMethodError:org.apache.commons codec.binary.Base64.en codeBase64String()的Java EE应用程序 [英] java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String() in Java EE application

查看:3707
本文介绍了java.lang.NoSuchMethodError:org.apache.commons codec.binary.Base64.en codeBase64String()的Java EE应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Java EE应用程序中,我需要的Base64编码/解码

I am developing a Java EE application in which I need Base64 Encoding/Decoding

所以我添加 commons- codeC-1.5.jar WEB-INF / lib目录的文件夹我的应用程序和使用

So I added commons-codec-1.5.jar in WEB-INF/lib folder of my application and used

import org.apache.commons.codec.binary.Base64;

在Java文件中

in the Java file.

在编译的时候,当我输入的Base64 ,它显示了连接codeBase64String 方法是可行的。但是在运行时它抛出一个异常,这样的:

During compile time, when I type Base64, it shows encodeBase64String method is available. But during runtime it is throwing an exception like this:

java.lang.NoSuchMethodError:org.apache.commons.codec.binary.Base64.encodeBase64String

我在构建路径的JAR,但我仍然不明白为什么它抛出我上面的错误。

I have the JAR in the buildpath, but still I don't understand why it throws me the above error.

推荐答案

这是方法<一个href=\"http://commons.apache.org/$c$cc/apidocs/org/apache/commons/$c$cc/binary/Base64.html#en$c$cBase64String%28byte%5B%5D%29\">introduced在下议院codeC 1.4。此异常表明您已经共享codeC别的地方在webapp的运行时类路径而获得的类装入precedence的旧版本。检查由web应用程序的运行时类路径覆盖所有路径。这其中包括包括的webapp / WEB-INF / lib目录 YourAppServer / lib目录 JRE / lib目录 JRE / lib / ext目录。最后,删除或更新有问题的旧版本。

That method was introduced in Commons Codec 1.4. This exception indicates that you've an older version of Commons Codec somewhere else in the webapp's runtime classpath which got precedence in classloading. Check all paths covered by the webapp's runtime classpath. This includes among others the Webapp/WEB-INF/lib, YourAppServer/lib, JRE/lib and JRE/lib/ext. Finally remove or upgrade the offending older version.

更新:根据的评论,你似乎无法找到它。我只能建议使用较新的方法来outcomment的code,然后把下面一行到位:

Update: as per the comments, you can't seem to locate it. I can only suggest to outcomment the code using that newer method and then put the following line in place:

System.out.println(Base64.class.getProtectionDomain().getCodeSource().getLocation());

这应该打印的绝对路径了它是从运行时加载的JAR文件。

That should print the absolute path to the JAR file where it was been loaded from during runtime.

更新2 :这似乎指向正确的文件。对不起,我不能再现在解释一下你的问题。所有我可以建议是使用像连接codeBase64(字节[]),然后不同的的Base64 方法只是构建一个新的字符串(字节)自己。或者你可以丢弃库和使用不同的Base64连接codeR,例如这个

Update 2: this did seem to point to the right file. Sorry, I can't explain your problem anymore right now. All I can suggest is to use a different Base64 method like encodeBase64(byte[]) and then just construct a new String(bytes) yourself. Or you could drop that library and use a different Base64 encoder, for example this one.

这篇关于java.lang.NoSuchMethodError:org.apache.commons codec.binary.Base64.en codeBase64String()的Java EE应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆