Reputation: 4594
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 libraryC:\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?
Upvotes: 12
Views: 39163
Reputation: 36
Maybe your jre system library is 1.8
or eclipse: Project Properties > java compiler > Errors/Warnings > Deprecated API
change Error to ignore/warning
Upvotes: 0
Reputation: 236024
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.
Upvotes: 2
Reputation: 49567
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)
Upvotes: 11
Reputation: 4118
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.
Upvotes: 3