java.lang.NoClassDefFoundError: java/util/Base64


In the following code, Base64 is used to encode AES encrypted data bytes to plain text for transfering via URL query parameter.


But when running this code on my coworker's machine, following exception is thrown


It's because that my execution environment is Java 8, but my coworker is using Java 7, and java.util.Base64 is introduced in Java 8.



To fix this issue, we can use Base64 class from Apache Commons Codec.

First add commons codec dependency to maven pom.xml file.

Next import Base64 class from commons-codec


Finally replace  Base64.getUrlEncoder().encodeToString to Base64.encodeBase64URLSafeString .

So the code will become like following