How to set up multiple source folders within a single Eclipse project?

前端 未结 4 415
旧巷少年郎
旧巷少年郎 2020-12-09 04:22

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 pr

相关标签:
4条回答
  • 2020-12-09 05:00

    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?

    0 讨论(0)
  • 2020-12-09 05:13

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

    0 讨论(0)
  • 2020-12-09 05:14

    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.

    0 讨论(0)
  • 2020-12-09 05:16

    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.

    0 讨论(0)
提交回复
热议问题