1

I'm trying to implement a new security bean, which relies on some Base64 encoding. In eclipse, the class compiles just fine, and indeed, it builds when deployed to tomcat, running locally; however, when the code actually reaches the line in which it invokes

Base64.encodeBase64String(rawBytes)

I get this

SEVERE: Servlet.service() for servlet analytics threw exception
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String([B)Ljava/lang/String;

I've taken care to import the type I want (org.apache.commons.codec.binary.Base64) and have tried changing the invocation to use the absolute package name of the method.

When I examine the pom.xml for the project, I see that the following exists, and it is the correct artifact, according to the apache site:

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
    </dependency>

Looking in the dependency hierarchy view in eclipse, commons-codec jar is included at compile time at version 1.4 (which contains the class in question).

A similar question here suggested purging the tomcat work directory, so I did that to no avail. I'm not exactly an expert on maven or tomcat, so any suggestions will be helpful. I'm aware that this is a highly specific problem and so I'm posting this in hopes of a few clues, and to clarify the problem to myself. I'll accept any answer that points in the right direction, though!

Ben
  • 4,980
  • 3
  • 43
  • 84

1 Answers1

1

Try to use the last version of the library:

<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>20041127.091804</version>
</dependency>
jddsantaella
  • 3,657
  • 1
  • 23
  • 39
  • Can't even launch the app after making that change: [ERROR] Failed to execute goal on project __.web.analytics: Could not resolve dependencies for project __:__.web.analytics:war:1.1.2-SNAPSHOT: Failure to find commons-codec:commons-codec:jar:20041127.091804 in http://dev01.__.corp/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of cond.repo.dev01-public has elapsed or updates are forced – Ben Jul 16 '12 at 18:06
  • It shouldn't be a problem since it is in the repository http://mvnrepository.com/artifact/commons-codec/commons-codec Anyway, try with previous version: 1.6 – jddsantaella Jul 16 '12 at 18:09
  • tried with 1.6, no difference, sadly. That is, I tried it before, and still get NoSuchMethod – Ben Jul 16 '12 at 18:09
  • well, now we're getting somewhere. I tried the reflection trick to determine the jar which was being used, and it was .m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar So what's the best approach to figuring out what's including that? – Ben Jul 16 '12 at 18:36
  • So problem is version, as I suspected. Take a look to this answer: http://stackoverflow.com/a/7688667/980472 – jddsantaella Jul 16 '12 at 18:53
  • right, I get that it's using the wrong jar, but then the question is, how do I determine which what is requiring that? since the offending jar is located in the maven repo, I assume it's a maven issue. Not knowing maven well, I'm unclear how to find the offending directive. That link you gave was helpful for determining the problem, but it doesn't address maven at all. – Ben Jul 16 '12 at 18:56
  • I see. If you are using Eclipse (one of the last version) or Eclipse Maven plugin, take a look to the maven dependency tree (is one of the pom.xml view) in order to find out what library is requiring /commons-codec-1.3.jar – jddsantaella Jul 16 '12 at 19:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13963/discussion-between-jddsantaella-and-ben) – jddsantaella Jul 16 '12 at 19:07