I am developing a Java EE application in which I need Base64 Encoding/Decoding
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;
in the Java file.
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
I have the JAR in the buildpath, but still I don't understand why it throws me the above error.
This question is related to
java
jakarta-ee
base64
Simply create an object of Base64 and use it to encode or decode, when using org.apache.commons.codec.binary.Base64 library
Base64 ed=new Base64();
String encoded=new String(ed.encode("Hello".getBytes()));
Replace "Hello" with the text to be encoded in String Format.
Base64 ed=new Base64();
String decoded=new String(ed.decode(encoded.getBytes()));
Here encoded is the String variable to be decoded
I faced the same problem with JBoss 4.2.3 GA when deploying my web application. I solved the issue by copying my commons-codec 1.6 jar into C:\jboss-4.2.3.GA\server\default\lib
Some Google tooling such as GWT has an embedded version of commons-codec with a pre-1.4 Base64 class. You may need to make such tooling JARs inaccessible to your code by refactoring your project such that only the parts of your code that need that tooling can see the dependency.
Try add 'commons-codec-1.8.jar' into your JRE folder!
@Adam Augusta is right, One more thing
Apache-HTTP client jars also comes in same category as some google-apis.
org.apache.httpcomponents.httpclient_4.2.jar and commons-codec-1.4.jar both on classpath, This is very possible that you will get this problem.
This prove to all jars which are using early version of common-codec internally and at the same time someone using common-codec explicitly on classpath too.
You need the Apache Commons Codec library 1.4 or above in your classpath. This library contains Base64 implementation.
Download this jar
It resolved my problem, this is 1.7.
Source: Stackoverflow.com