Eclipse如何知道com.sun是受限制的API? [英] How does Eclipse know that com.sun is a restricted API?
问题描述
我正在使用 Guava
中的 ClassPath.getAllClasses
在运行时类中实现某些接口的类。与 rt.jar
一起使用时,它从 sun。*
和类似的软件包中找到许多类,我想过滤
I'm using ClassPath.getAllClasses
from Guava
to find in runtime classes that implement a certain interface. When used with rt.jar
it finds many classes from sun.*
and similar packages and I'd like to filter them out.
我想重用Eclipse和其他Java编译器使用的机制来警告受限API。
I want to reuse the mechanism used by Eclipse and maybe other java compilers to warn about restricted API. Does this information reside JRE or hardcoded into Eclipse?
推荐答案
此信息存储在所谓的 Eclipse内的执行环境配置文件。
This information is stored in so-called Execution Environments profiles inside of Eclipse.
因为这些配置文件最初是OSGi的东西(请参见 Bundle-RequiredExecutionEnvironment
),配置文件存储在 org.eclipse.osgi *。profile
文件中的插件/捆绑包每个都包含可访问软件包的白名单( org.osgi.framework.system.packages
),e。 G。此处 JavaSE-1.8
。
Because these profiles are originally an OSGi thing (see Bundle-RequiredExecutionEnvironment
), the profiles are stored in the org.eclipse.osgi plugin/bundle in *.profile
files that each contains a whitelist of the accessible packages (org.osgi.framework.system.packages
), e. g. here for JavaSE-1.8
.
如果创建新的Java项目,则可以选择
If you create a new Java project you can choose either
- 一个执行环境JRE ,它会为您导入访问限制错误e。 G。
sun。*
软件包或 - 一个特定的JRE,对JRE软件包没有任何访问限制
- an execution environment JRE which gives you access restriction errors for imports of e. g.
sun.*
packages or - a specific JRE without any access restriction to JRE packages
创建项目后,可以在 Project> Properties:Java Build Path 中更改所选的JRE。 ,通过选择JRE并点击 Edit ... ,选择 Libraries 。
After project creation the chosen JRE can be changed in Project > Properties: Java Build Path, tab Libraries by selecting the JRE and clicking Edit....
此外,由于 Java平台模块系统, Java 9引入的JRE本身限制了对某些软件包的访问(而不是文件 rt.jar
,而文件是 modules
)。
In addition, since the Java Platform Module System, introduced with Java 9, the JRE itself restricts access to some packages (and instead of the file rt.jar
there is the file modules
).
这篇关于Eclipse如何知道com.sun是受限制的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!