Project using a source framework with restricted access

Layout on file system

Steps for defining corresponding projects

  1. Open a Java perspective, select the menu item File > New > Project.... to open the New Project wizard.

  2. Select Java project in the list of wizards and click Next.

  3. On the next page, type "Framework" in the Project name field.

  4. In Contents group, change selection to Create project from existing source.

    Click Browse... and choose the D:\Framework directory.

    Layout 61

    Click Next.

  5. On the next page, verify that directory JavaSourceFiles has been automatically added as source folder.

    Expand it to preview your project source folder contents:

    Layout 62

  6. Click Finish.
  7. In Java perspective, type Ctrl+N to open New wizards dialog.

    Select Java project in the list of wizards and click Next.

  8. On the next page, type "Product" in the Project name field.

  9. In Contents group, change selection to Create project from existing source.

    Click Browse... and choose the D:\Product directory.

    Layout 63

    Click Next.

  10. Let's add a dependency to source framework project...

  11. On the next page, verify that directory JavaSourceFiles has been automatically added as source folder.

    Select Projects tab.

    Layout 64

    Click Add....

  12. In Required Project Selection, check "Framework".

    Layout 65

    Click OK.

  13. Now, let's put access rules on source framework content to authorize, discourage or forbid access to "Framework" source folders, package and classes...

  14. In Projects tab, select "Access rules" of "Framework" depending project.

    Layout 66

    Click Edit....

  15. In Type Access Rules, click Add....

    Layout 67

  16. In Edit Access Rule, select "Forbidden" for Resolution.

    Type "**/forbidden/**" in Rule Pattern field.

    Layout 68

    Click OK.

  17. Add another access rule:

    Resolution: "Discouraged" and Rule Pattern: "**/internal/**".

  18. Your access rules now look as follows:

    Layout 69

    Click OK.

  19. Dependent project has now 2 access rules set.

    Layout 6a

    Click Finish.

  20. You now have a Java project which contains the source of "Product" and which is using the source of "Framework".

    Some packages of the project "Framework" are restricted and if you try to import them, compiler displays either warnings or errors depending on your restriction level:

    Layout 6b

Related concepts

Java projects
Java views

Related tasks

Working with build paths
Creating a new Java project
Creating a Java project with source folders
Creating a new source folder
Using the Package Explorer

Related reference

New Java Project Wizard
Package Explorer View