9

I'm trying to convert old project into maven project. But when project is maven then it shows warnings on class with import:

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

Access restriction: The type 'BASE64Decoder' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')

So what is the problem with it?

3
  • 2
    refer stackoverflow.com/questions/860187/… Commented May 30, 2017 at 17:47
  • 3
    You're not, generally, supposed to use dependencies from sun.misc. Commented May 30, 2017 at 17:57
  • 1
    Java 8 has a standar Base64 encoder/decoder. Guava has one too. Apache commons-codec has one too. Commented May 30, 2017 at 18:07

2 Answers 2

10

You can either replace sun.misc.BASE64Encoder & sun.misc.BASE64Decoder with other BASE64 class e.g. Apache commons or use:

java.util.Base64;
Base64.getDecoder().decode(...);
Base64.getEncoder().encodeToString(...);
Sign up to request clarification or add additional context in comments.

Comments

8

All sun.* and com.sun.* packages are private to a Java implementation. Any future release of Java may alter them, possibly in ways which may break application code that relies on them.

In contrast, all classes in java.*, javax.* and javafx.* packages are set in stone. Their names and their public members will not change and will not be removed (except, in theory, the deprecated ones).

That is why you’re getting a message that those classes are not part of the public API. They are not meant for public consumption.

As of Java 8, you should be using java.util.Base64 instead. However, it looks like you’re using Java 7, so you’ll want to use DatatypeConverter.parseBase64Binary and DatatypeConverter.printBase64Binary instead.

It should also be mentioned that Java 9, which is expected to be released in July 2017, will not allow programs to access sun.* classes. See https://mreinhold.org/blog/jigsaw-module-system .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.