问题
I apologize if this has been asked before, but I believe that for me, this question falls under the "I have no idea what I should even google" category.
So, as a noobie to the coding world, I have only recently begun delving into projects that encompass more than a few source files. I am beginning my first "big" project, and before I begin, I would like to know the best way to go about managing many different pieces of a system.
For example: I have Project0 which is built from the pieces A through Z. Each piece is comprised of 50 separate source files, src0 through src50. What is the proper folder structure for this set up? Also, is this a perfect use for Java's package structure?
回答1:
Names like "A" to "Z" do not convey much meaning. It's the same for "src0" to "src50".
But if that's really what you want, in a typical Java project it may look like this:
.../Project0/
|
+----/src/com/meff/a/
| |
| +-Src0.java
| +-Src1.java
| .
| .
| .
| +-Src50.java
|
+----/src/com/meff/b/
+-Src0.java
+-Src1.java
.
.
.
+-Src50.java
Once again, such a naming scheme would be absolutely terrible. I just put it there because that's the example you used and it may help you organize your first project...
So you should use directories to represent your packages (and by conventions they should be in lowercase). Your "pieces" "A" through "Z" [sic] becomes "package" "a" through "z".
Then your source code files become Java classes (and by conventions they should be starting with an uppercase).
It's also convenient to use a domain name you own as part of your hierarchy (I know you don't own "meff.com", but you get the idea).
So your "src0" from your "piece A" [sic] becomes a Src0.java file located in .../Project0/src/com/meff/a/ and looks like this:
package com.meff.a;
public class Src0 {
...
}
Note that it's typical to have a src/ directory. If you're adding unit tests to your projects, for example, you may also to add a test directory at the same level as the src/ directory, etc.
Hope it helps and change your "A to Z" and "src0 to src50" to something meaningful : )
来源:https://stackoverflow.com/questions/8640789/proper-folder-structure-for-lots-of-source-files