Question

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?

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.

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.

Was it helpful?

Solution

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 Forbidden or Discouraged the 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.

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.

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

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 Discouraged access rules if you check the Combine rules with the access rules of the exported project entries.

OTHER TIPS

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.

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

  • 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 :)

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/**"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top