Import classes in some special jar packages

Source: Internet
Author: User

Import special jar settings

In general development may look at the source code of the API, you can sometimes imitate the code in the API to do some research, but some special jar packages in the class report can not import errors:

The import Sun.misc.ProxyGenerator is never used
-Access restriction:the type ' proxygenerator ' isn't API (restriction on required library ' C:
\program Files\java\jdk1.7.0_75\jre\lib\rt.jar '.

For example, the Proxygenerator class in the above Sun.misc, in order to study the Java dynamic Proxy needs to use this kind to do some development work, the following provides the network to import the special jar the solution and own practice to do some summary.


The first and simplest scenario:

1, open the project Properties "Java build Path" Select JRE System Library remove;

And then add the JRE system library again;

2, click Add Library Next to select the corresponding JDK version (recommended as the beginning of the same version) finish.

By doing this, the special jar import error disappears.

The specific actions are as follows:




The second scenario sets the access rules property for the JRE System Library

1, open the project Properties Java build Path Select the JRE System Library click the triangle on the left to open the Drop-down menu, double-click Access rules to open its properties;

2, click on the right Add "open access rules settings" Select resolution for accessible "according to the prompts in the following rule pattern input corresponding pattern;

Pattern can be entered * * on behalf of all the packages can be imported, you can enter the corresponding package path below the class can access, such as sun/misc/** and so on;

3, all the choice is completed step by step OK, back to work space, red error that disappears.

The specific actions are as follows:





The third scenario modifies the Java compiler settings

1, open windows "click Preferences" Choose Java "Open compiler;"

2, select Errors/warnings "Click on the right side of the deprecated and trstricted API options" to find forbidden reference (access rules) menu to change the Drop-down box to the right of the menu to warning;

3, the last step OK can be.

The specific actions are as follows:





Summarize:

Through the above three kinds of schemes can achieve the import of special packages (sun.*, com.sun.*, etc.), access to the inside of the class; However, this operation will have a certain risk, for the future of the code can be extended, universal, security, etc., because these packages are not the J2SE specifications declared in the class.

This means that these classes may be available under Windows but are not available on Linux or other platforms, or that these classes may be deleted in a version of the JDK, or that the classes themselves have security implications, and so on, be careful.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.