12

I'm creating an image watermarking program in java and I imported the followings:

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

but I get an error that says:

Access restriction: The type JPEGCodec is not accesible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar

Does someone know a way to solve this, or what library should I add in order to access that and where I find that library?

Cœur
  • 37,241
  • 25
  • 195
  • 267
adrian
  • 4,574
  • 17
  • 68
  • 119

4 Answers4

11

Take a look here Link

1. Open project properties.
2. Select Java Build Path node.
3. Select Libraries tab.
4. Remove JRE System Library.
5. Add Library JRE System Library.

As Milad suggested

Even though this WILL work, this goes against all recommended Java Runtime policies. The best practice is to avoid using rt.jar (or any other Sun supplied runtime library for that matter, like tools.jar)

RanRag
  • 48,359
  • 38
  • 114
  • 167
3

These are in rt.jar, the jar file used as run-time facilities by the JVM, and I would strongly recommend you against adding it as a dependency to your project.

See why here.

The correct way to do what you want to do is described here.

Milad Naseri
  • 4,053
  • 1
  • 27
  • 39
2

The problem is, that you're importing libraries from the sun.com.* package. Oracle actually discourages the use of these packages, since they could be removed in future releases or may not be available in all JVM implementations.

It's possible that your IDE (which one are you using?) is configured for generating errors if you try to import sun.com.* libraries, in that case a configuration change will allow you to use those libraries, but it wouldn't be a good idea anyway. You should look for other alternatives to the functionality you seek, using libraries with no access restrictions.

Also, if what you want is to simply read or write a JPEG file, take a look at the ImageIO class, there are plenty of useful methods in there.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
0

Maybe your jre system library is 1.8

or eclipse: Project Properties > java compiler > Errors/Warnings > Deprecated API

change Error to ignore/warning

Sitan
  • 36
  • 1
  • 6