Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does combineaccessrules mean in Eclipse classpaths?

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.

like image 833
skaffman Avatar asked Jun 23 '09 11:06

skaffman


People also ask

What is classpath in Eclipse project?

The . classpath maintains the project's source and target references for Java compilation and compressed file or project dependencies. This configuration is maintained through the Java Build Path page in the project's properties.

What is .classpath and .project files?

Basically, . project files store project-settings, such as builder and project nature settings, while . classpath files define the classpath to use during running.

Can I delete .classpath file?

To delete an existing class path variable: From the menu bar, select Window > Preferences. Expand the Java category in the left pane, and select Classpath Variables. Select the variable(s) you want to delete in the Defined class path variables list and click the Remove button.

How do I find the classpath in eclipse?

In Eclipse, go to Window > Preferences > Java > Build Path > Classpath Variables.


2 Answers

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.

like image 142
Csaba_H Avatar answered Oct 08 '22 09:10

Csaba_H


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

like image 41
Spyder Avatar answered Oct 08 '22 08:10

Spyder