Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access restriction: The type 'BASE64Decoder' is not API [duplicate]

Tags:

java

base64

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?

like image 566
user8049659 Avatar asked May 30 '17 17:05

user8049659


People also ask

How do I resolve access restrictions in eclipse?

Assuming you are using Eclipse + m2e maven plugin, if you get this access restriction error, right click on the project/module in which you have the error --> Properties --> Build Path --> Library --> Replace JDK/JRE to the one that is used in eclipse workspace. I followed the above steps and the issue is resolved.

Is there an API for Base64 decoder?

Access restriction: The type 'BASE64Decoder' is not API (restriction on required library 'C:\Program Files\Java\jre7\libt.jar') So what is the problem with it? You can either replace sun.misc.BASE64Encoder & sun.misc.BASE64Decoder with other BASE64 class e.g. Apache commons or use:

Is the type'application'is not API?

And now error Access restriction: The type 'Application' is not API (restriction on required library rt.jar) is solved. 10 points on why we are still using primitive data types in java ?

How to enable JRE for application type'application is not API'?

Solved : Access restriction: The type 'Application' is not API (restriction on required library rt.jar) 1 Step 1.1: click Windows, Preferences, 2 Step 1.2: Type jre 3 Step 1.3: Select Standard VM > 4 Step 1.4: JRE home and JRE name More ...


2 Answers

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(...);
like image 76
CuE Avatar answered Oct 13 '22 09:10

CuE


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 .

like image 39
VGR Avatar answered Oct 13 '22 09:10

VGR