Martyn
Martyn

Reputation: 6383

Base64 cannot be resolved (Java 1.7)

I have the following snippet and I have some unresolved classes - mainly, Base64

String auth = username + ":" + password; 
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));
String authHeader = "Basic " + new String(encodedAuth);
request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

I've tried to import the commons-codec maven repository but in Eclipse it still says cannot resolve class:

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

We're kinda stuck for now using JDK7 which may be the issue. Is this Base64 class only available from Java 8? Otherwise, how do I import it into my application?

Upvotes: 1

Views: 6887

Answers (1)

jbx
jbx

Reputation: 22128

If you check the Javadoc, it clearly says that Base64 is Since 1.8.

https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html

Not sure about the commons-codec one, you must have something wrong in Eclipse (not suprised considering how crap its Maven integration is).

Upvotes: 1

Related Questions