简体   繁体   中英

java.lang.NoMethodError : org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString

I am getting the following exception in my web application:

 java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError:     org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString([B)Ljava/lang/String;

The commons-codec-1.5.jar is added in my classpath. I am building it using Ant and have added the dependencies manually. Through other discussions on the same issue I found out that adding the source of the this library can solve the issue but that didn't work for me. I also read that having another library with the same class can cause the conflict and possibly that class may not have this method which results in the error. However, I have double checked that there is no other version of the same library. Is it possible that some other library has the same class in it? If yes, then how can I identify that and resolve the problem?

As you allude to in your question, this is caused when a different version of the Base64 class is used at compile time to the one picked up at runtime. Since you are using Ant (rather than Maven for example), it should be easier to find the culprit since you don't have to worry about transitive dependencies.

The first thing to do is use your IDE to open the class Base64 (ctrl+N in IntelliJ), this will highlight how many different version of this library are on your classpath. In my case there were 2. If you have more than one then you've found your culprit.

If you only have one version on your classpath, then the only other place this class can reside is in the lib directory of Tomcat. You may have to open the jar files manually to see if any contain the same package org.apache.commons.codec.binary... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM