tags:

views:

3297

answers:

4

I have several somewhat separate programs, that conceptually can fit into a single project. However, I'm having trouble telling Eclipse to make several folders inside a project folder.

A simple form of the structure would be:

/UberProject
/UberProject/ProgramA/
/UberProject/ProgramA/com/pkg/NiftyReader.java
/UberProject/ProgramB/
/UberProject/ProgramB/com/pkg/NiftyWriter.java

That is, ProgramA and ProgramB are both projects (in fact, they're currently existing Java projects), which conceptually fit into UberProject.

I don't think I'm supposed to make UberProject be a Java project; it's not a classpath, for instance. ProgramA and ProgramB do seem like they should be Java projects (they might use different build dependencies as well), but I see no way in Eclipse 3.3 to create two folders under UberProject that are intended to contain Java code. I thought about adding a .project file to each of the two sub-projects, but I'm not sure that's appropriate, either. Eclipse help isn't being helpful, and I didn't see anything on SO about this specific problem.

Just to be clear: assume as given the necessity of the existence of UberProject. UberProject can be a Java project, or not; it doesn't matter. (Incidentally, it does contain other folders that do not contain Java code.)

+1  A: 

Do you need UberProject? I have the same layout but have multiple top-level projects created with File|New project. If not, can you make it a General rather than Java project?

Mat
It is a necessary project, yes; sorry if that wasn't clear. Otherwise, I'd just use several separate Java projects, too. I edited the question.
Paul Brinkley
+3  A: 

There are probably several ways to do this:

1) UberProject is your JavaProject. Right click ProgramA -> Build Path -> Use as source folder. Right click ProgramB -> Build Path -> Use as source folder. Both ProgramA and ProgramB will do incremental builds to the same directory.

2) Two java projects (ProgramA and ProgramB). You can use UberProject as your eclipse workspace which would be easiest or you can use an outside workspace and import ProgramA and ProgramB as external projects.

There are probably other ways as well (maven multi-module project). Your choice probably depends on whether you have cyclic dependencies between projects. It should be relatively easy to try both 1 and 2 and see what works best for you.

(1) seems to work, or at least, get me closer. (It now refuses to use the default Java builder for some reason.) Despite my intuition, UberProject did indeed need to be a "Java project".
Paul Brinkley
...the Java Builder problem was fixed by hand-editing the .project file.
Paul Brinkley
+1  A: 

So you can do it via having two Java projects in your workspace.
Then the question is how to group the two projects together under "UberProject"

One way is to have an "UberProject" workspace, and switch workspaces between UberProjects. An alternative is to define "UberProject" as a working set (Window:Working Sets) and add PrmgramA and ProgramB as projects of that working set. Select that working set, and you see only those projects.

You can have one java project, and define multiple source folders for it. That is normally do that for "main" vs "test" hierarchies within the same project.

There are ways, and ways. Pick one that works for you :-)

evnafets
+1  A: 

You can have multiple source directories in a single project, but your description makes it sound like you want multiple sub-projects in a project, which eclipse doesn't allow (as far as I know).

If you really just want multiple source directories, where ProgramA, ProgramB, etc. contain only java files and nothing else, then you can do this relatively easy. Right-click on your project in the package explorer, and select Build Path -> Configure Build Path.... In the dialog that pops up, make sure Java Build Path is selected in the left pane, click the Source tab, then click the Add Folder... button. Pick ProgramA from the list, and repeat for ProgramB, etc.

If you want each source folder to have its own output folder, just check the Allow output folders for source folders checkbox and edit the output folders as desired.

If that is not, in fact, what you want to do, then another option might be to group your projects into a working set. A working set is not an UberProject, but it does help keep your projects organized in the package explorer.

Jason Day