Eclipse 类路径中的 combineaccessrules 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1032084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:49:38  来源:igfitidea点击:

What does combineaccessrules mean in Eclipse classpaths?

javaeclipseclasspath

提问by skaffman

This has been bugging me for years now, and I thought one of you fine people would know - in Eclipse's .classpath files, what is the combineaccessrules attribute of the classpathentry element actually used for?

这已经困扰我多年了,我想你们中的一个人会知道 - 在 Eclipse 的 .classpath 文件中,实际使用的 classpathentry 元素的 combineaccessrules 属性是什么?

I can see in the Java Build Path config dialog that it can be maniuplated, but I can't think of a good use case for it. If I muck about with the settings, or modify the .classpath file manually, it doesn't seem to have any effect.

我可以在 Java Build Path 配置对话框中看到它可以被操纵,但我想不出一个好的用例。如果我对设置进行了处理,或者手动修改 .classpath 文件,它似乎没有任何效果。

I'm hoping someone else has put it to good use, and I can steal their ideas. Basically, it's an itch I'm trying to scratch.

我希望其他人已经充分利用了它,我可以窃取他们的想法。基本上,这是我想抓挠的痒。

采纳答案by Csaba_H

With proper use of access rules you can prevent using "internal" and/or "non-api" classes and methods. When you add a class or package as Forbiddenor Discouragedthe compiler show an error or warning when you use that class or class from the specified package. For a longer introduction of access rules you should read this short article.

通过正确使用访问规则,您可以防止使用“内部”和/或“非 API”类和方法。当您将类或包添加为ForbiddenDiscouraged 时,编译器会在您使用指定包中的该类或类时显示错误或警告。有关访问规则的详细介绍,您应该阅读这篇简短的文章

For using combine access rules imagine the following situation:

要使用组合访问规则,请想象以下情况:

  • You have 2 projects, A and B.
  • On the classpath of project A there is a jar file that is exported. The jar contains some "stable api", "unstable api" and "non-api" public classes.
  • Project B depends on project A.
  • 你有 2 个项目,A 和 B。
  • 在项目 A 的类路径上,有一个导出的 jar 文件。jar 包含一些“stable api”、“unstable api”和“non-api”公共类。
  • 项目 B 依赖于项目 A。

You do not allow using "non-api" classes in project A so you set some Forbiddenaccess rules on those classes / packages.

您不允许在项目 A 中使用“非 api”类,因此您在这些类/包上设置了一些禁止访问规则。

In project B you do not allow using "non-api" as well, but you do want to get a warning when using "unstable api". In this case in project B you only have to set the additional Discouragedaccess rules if you check the Combine rules with the access rules of the exported project entries.

在项目 B 中,您也不允许使用“非 api”,但您确实希望在使用“不稳定的 api”时收到警告。在这种情况下,在项目 B 中,如果您将合并规则与导出的项目条目的访问规则一起选中,则您只需设置附加的不鼓励访问规则。

回答by Spyder

Access rules are handy little things, but dangerous. They exclude a source file from the project compiler but leave the file intact in the filesystem.

访问规则是方便的小东西,但很危险。它们从项目编译器中排除源文件,但在文件系统中保持该文件完好无损。

The project I work on has a bootstrap class in one of our source folders, but if we include the entire folder the project classpath it won't compile (it's a long story and the build process handles this).

我工作的项目在我们的源文件夹之一中有一个引导程序类,但是如果我们包含整个文件夹,项目类路径将无法编译(这是一个很长的故事,构建过程会处理这个问题)。

So we use an eclipse access rule to exclude it and it never bothers us during development. This means we can't easily change the code, but it's one of those classes that literally hasn't been touched in years.

所以我们使用eclipse访问规则来排除它,它在开发过程中永远不会打扰我们。这意味着我们不能轻易更改代码,但它是多年来几乎没有接触过的类之一。

Combine Access Rules, judging by the JavaDoc, is a real edge use case. To use it you would have to have:

从 JavaDoc 判断,组合访问规则是一个真正的边缘用例。要使用它,您必须拥有:

  • an access rule in an exported source entry of one project
  • a link to that project from a parent project
  • a need to combine the access rules of the sub project with the parent
  • 一个项目的导出源条目中的访问规则
  • 从父项目到该项目的链接
  • 需要结合子项目和父项目的访问规则

I really can't say how it would be useful, but I hope that at least answers your "what is it" question :)

我真的不能说它会有什么用处,但我希望至少能回答你的“它是什么”的问题:)

回答by akf

although i have never used it myself, a little bit of into can be found here.

虽然我自己从未使用过它,但可以在这里找到一点点。

whether the access rules of the project's exported entries should be combined with this entry's access rules

项目导出条目的访问规则是否应该与该条目的访问规则结合

the access rules would be something like including "com/tests/**"

访问规则类似于包括“com/tests/**”