This question is not a duplicate of java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder.
I am trying to update the Java Version (to 11) in my app and one of the libraries in my app uses sun.misc.BASE64Encoder class, so I inevitably get this exception:
Caused by: java.lang.ClassNotFoundException: sun.misc.BASE64Encoder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Now, the way to solve would be to use java.util.Base64 or apache commons as the other answers suggest. However, the problem is, this library belongs to a third party and I don't have the source code for it. There doesn't seem to be a new version that is not using these classes. So, to work around this issue, I did the following:
- Created package
sun.misc - Copied both
BASE64EncoderandCharacterEncoderclasses in this package
But now, I get a compilation error saying The package sun.misc conflicts with a package accessible from another module: jdk.unsupported.
Is there any way to get around this error? If not, can I add a jar to the dependencies that contains these classes? I am just trying to make sure these classes are available to that third party library at runtime (either via my own source code or via a jar that bundles these classes in).