Search code examples
javabase64

The import sun.misc.BASE64Decoder cannot be resolved when the project is imported into Eclipse


I have this old project which was implemented a long time ago, and it uses sun.misc.BASE64Decoder and sun.misc.BASE64Encoder. When I imported the project into Eclipse it is showing me the that their imports cannot be resolved to a valid object.

I have tried using all the recommended methods on Stack overflow like turning errors into warnings. For references here's a screenshot

Thanks in advance for the help :)


Solution

  • If you're using JDK 8+ then the reason is likely that the package for Base64Encoder and Base64Decoder has changed from sun.misc to java.util (see Is Java 8 java.util.Base64 a drop-in replacement for sun.misc.BASE64?)

    You could either use an older JDK or replace the package.

    Normally you don't have to expect the JDK packages to change - except for javax.* and sun.*. As far as I know these packages were originally for vendor specific or experimental classes and IIRC the Java docs explicitly mention that this could change - although this rarely happens.