what library I need so I can access this com.sun.image.codec.jpeg in Java?

前端 未结 4 2066
忘掉有多难
忘掉有多难 2021-02-07 21:29

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.JPE         


        
相关标签:
4条回答
  • 2021-02-07 21:38

    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)

    0 讨论(0)
  • 2021-02-07 21:51

    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.

    0 讨论(0)
  • 2021-02-07 21:53

    Maybe your jre system library is 1.8

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

    change Error to ignore/warning

    0 讨论(0)
  • 2021-02-07 22:01

    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.

    0 讨论(0)
提交回复
热议问题