Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

19 Nov 2009

Access restriction error on Eclipse - type resouce not accessible

Mounting an old project on a fresh install of Eclipse I got a few errors regarding access restriction to some methods and types from Sun's java 6 library.


Description Resource Path Location Type
Access restriction: The method createJPEGEncoder(OutputStream) from the type JPEGCodec is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar ImageCaptchaServlet.java «path» line 43 Java Problem

Description Resource Path Location Type
Access restriction: The method encode(BufferedImage) from the type JPEGImageEncoder is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar ImageCaptchaServlet.java «path» line 45 Java Problem

Description Resource Path Location Type
Access restriction: The type JPEGCodec is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar ImageCaptchaServlet.java «path» line 16 Java Problem

Description Resource Path Location Type
Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar ImageCaptchaServlet.java «path» line 17 Java Problem




This situation can be solved as follows:

1 - Goto to the Java Compiler section of the Project Properties dialog and then Errors and Warnings.
2 - Check Enable project specific settings
3 - Inside Deprecated and restricted API change the Forbidden reference (acess rule) to Warning or Ignore
Enhanced by Zemanta

10 Feb 2009

How to install HTTPS Certificate at Java environment

To install an HTTPS certificate to be used by a Java application, using Java 6 we can use the following procedure:

$JAVA_HOME/bin/keytool -import -trustcacerts -alias [THE CERTIFICATE ALIAS] -file [THE CERTIFICATE FILE] -keystore $JAVA_HOME/lib/security/cacerts

Note: the default password for 'cacerts' is 'changeit'

14 Jan 2009

Make HTTP request with authentication using JAVA

Here is an example on how to make an http request to a page that requires authentication using Java language.


// Create the connection
URL url = new URL (urlStr);
URLConnection uc = url.openConnection();

// Prepare authentication data
String authData = username + ":" + password;
String encodedAuthData = new sun.misc.BASE64Encoder().encode (authData.getBytes());
// Set authentication data
uc.setRequestProperty ("Authorization", "Basic " + encodedAuthData);

// Get the contents
InputStream is = uc.getContent();