Products sharing a common source framework

Layout on file system

Steps for defining corresponding projects

  1. Click Opens the Java perspective Window > Open Perspective > Other... > Java to change to the Java perspective.

  2. Click Opens the New Java Project wizard File > New > Other... > Java Project to open the New Java Project wizard.

  3. Type "Product1" in the Project name field. Click Next.

    New Java Project wizard

  4. On the next page, Select "Product1" source folder.

    Click Link additional source link in Details pane or button Link Additional Source to Project in view bar.

    Java Project Source setup

  5. In Link Source click Browse.... and choose the D:\Product1\JavaSourceFiles directory.

    Type "src" in the Folder name field.

    Link Source dialog

  6. Click Finish to validate and close the dialog.

  7. Again, Select "Product1" and click Link additional source link in Details pane or button Link Additional Source to Project in view bar.

    Java Project Source setup

  8. In Link Source click Browse.... and choose the D:\Framework\JavaSourceFiles directory.

    Type "src-common" in the Folder name field.

    Link Source dialog

  9. Click Finish to validate and close the dialog.

    Your project source setup now looks as follows:

    Java Project Source final setup

  10. Click Finish.
  11. Create project "Product2" repeating steps 2 to 5 choosing D:\Product2\JavaSourceFiles directory for source folder instead.

  12. Click on Finish to create the project immediately.

  13. Now, we'll see how to add a linked source folder when project is already created in workspace...

    Edit project "Product2" properties and select Java Builder Path page.

    On Source tab, click Link Source....

    Java Build Path Properties Source tab

  14. In Link Source click Browse.... and choose the D:\Framework\JavaSourceFiles directory.

    Type "src-common" in the Folder name field.

    Link Source dialog

  15. Click Finish to validate and close the dialog.

    Click OK to apply project "Product2" properties changes.

  16. You now have two Java projects which respectively contain the sources of "Product1" and "Product2" and which are using the sources of "Framework".

    Created Java projects in Workspace

Note: Files in "src-common" are shared. So editing "Common.java" in "Product1" will modify "Common.java" in "Product2". However they are compiled in the context of their respective projects. Two "Common.class" files will be generated; one for each project. If the two projects have different compiler options, then different errors could be reported on each "Common.java" file.

Related concepts

Java projects
Java views

Related reference

New Java Project Wizard
Package Explorer View