Search code examples
javaeclipseimportsun

Import sun class in Java-Eclipse


I'm tring to:

import sun.security.provider.SecureRandom;

And Eclipse is suggesting me to Search repositories for 'sun.security.provider'. It can see only the java.security.SecureRandom...

Access restriction: The type 'SecureRandom' is not API (restriction on required library '/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar')

My BuildPath has the JRE System Library [JavaSE-1.7]

What can I check?


Solution

  • The libraries in Eclipse have Access rules, so you cannot use every class (although they are present). These rules include the java.*, javax.* and the org.* packages (screenshot below).

    When you change the library to use a specified JRE/JDK there are no access rules (second screenshot). You can change them by selecting the library and pressing the "Edit..."-button on the right side. In the new window you choose "Alternate JRE" (third screenshot).

    But what Pshemo said is correct, too, you should not use these libraries.


    JRE with Access rules:
    Eclipse BuildPath

    JRE without Access rules:
    Eclipse BuildPath

    Dialog:
    Eclipse BuildPath