Alan Evangelista
Alan Evangelista

Reputation: 3163

Eclipse: project directory isolated from source directory

I have Java code managed by a Git repository. Currently, the directory structure is

myProject    | 
    -- src
    -- bin
    -- lib
    -- .git

Currently, each developer creates its own development environment under his desired tool (Eclipse/Netbeans). I would like to create a Eclipse project for this code and add it to my source repository, so that new Eclipse developers don't need to create a new project and set the dev environment manually. I'd like to have this:

myProject
   | 
    -- src
    -- bin
    -- lib
    -- .git
    -- eclipse
     |
      -- .settings/
      -- .project
      -- .classpath

From what I've read in the web, I don't need to add the .metadata directory to the repository. Also, I know I could have dependency problems in some situations if I add the .classpath folder to the repository, but I prefer to not support these problematic situations (eg different Java compilers) than forcing the dev to manually set the classpath. Finally, I don't want to use Maven in this project.

Concisely, my requirements are - I don't want to put Eclipse project files in the root folder - I don't want to duplicate the code inside eclipse folder (that's what happens when I try to import existing code into an isolated project folder). I want it to reference the source files I have in the folder named 'src' - I want to configure Eclipse to put the compilation output (.class files) in the 'bin' folder.

That latter item I was able to set when creating the project, but I wasn't able to configure Eclipse to reference the source code (not duplicate it) without choosing a source parent directory as the project folder.

Any help is much appreciated.

Upvotes: 2

Views: 2371

Answers (2)

davidfmatheson
davidfmatheson

Reputation: 3567

  1. Create your directory structure above with the eclipse subdirectory.
  2. Create a new Dynamic Web Application (or whatever, assuming based on .settings)
  3. Uncheck Use default location and specify your eclipse directory, hit Next
  4. Remove the lone source folder
  5. Leave Generate web.xml... unchecked
  6. File > New > Folder and click Advanced>>
  7. Use Link to alternate location (Linked Folder) to create src and bin directories that are linked to the top-level src and bin.
  8. Right-click on the project and use File > New > Source folder to add the linked src folder with an output directory of bin
  9. Move WebContent to WebContent.bak and create a new WebContent directory that is linked to the top level.
  10. Move the contents of WebContent.bak to WebContent
  11. Manually edit eclipse/.settings/org.eclipse.wst.common.component to change WebContent.bak to WebContent (is there a setting for this? couldn't find it)
  12. Refresh the project
  13. Right-click the project and select Java EE Tools > Generate Deployment Descriptor Stub

Upvotes: 1

Colin D
Colin D

Reputation: 5661

You will need to create a project in the place you want it, and then use 'linked source' directories to point to your actual source code.

more information:

Store eclipse .project files outside the project directory

Upvotes: 2

Related Questions