What do I need to add apart from the obvious (src, dist) to my version control system from a NetBeans Java project directory? Can I drop the entire build directory? Should I add the nbproject directory as I'm working on the same proj开发者_高级运维ect on a different machine as well?
I would like to drop at least the build directory because anytime the application doesn't compile I get problems with git as there's a ton of files missing which git considers as being removed.
Note: this answer applies to NB 6.8 (which is what I am using right now) and probably also applies to most of the 6.x versions that are likely to be out there in the wild.
The short answer: Use the 'Import into Repository' menu item to do the initial check in. The IDE will check in the stuff that it thinks is necessary.
It is a bit hard to find. Select your project in the Project explorer. Open the Team menu from the menu bar. Once you click it, you will see something like:
Kenai>
------
CVS>
Mercurial>
Subversion>
______
The Import into item is a sub item of CVS/Mergcurial/Subversion.
If you you are committed to doing the check-in 'by-hand' here is a list of the stuff the IDE usually pushed into a repository:
- src dir (and all sub files and folders)
- test dir (and all sub files and folders)
- nbproject dir (and all files and folders -- EXCEPT the 'private' folder and its content)
- build.xml
- manifest.mf
There is a similar question asked about Eclipse awhile ago, and although some of the specifics the IDE may be different, the principle of what to put in version control is the same.
Basically, anything that you don't generate.
Exceptions to this may be the dependent jars. Whether you include them or not really depends on whether you have a common library location that others can reference or not. As a habit, I have always had environments with common locations instead of putting it under control for each project (after all, how many times do you want to store log4j and all its version under source control). Of course, we now user maven for this so that issue is taken care of (see my answer dealing with Maven and Eclipse in the same question linked above).
You source code, resource files (images, config files, etc) and build scripts (in Netbeans all the the ant build files) should be in the repository.
Do not put the dist/build directory in there. It is generally not a good idea to put built artifacts (class files, the project's jar, etc.) in source control.
However sharing the Netbeans meta-data can be handy while working on the same project from different machines.
You should put as much under version control as much you can. Versioning something that wont change has zero cost, realizing later that you can't recover a state you need to is fatal. Storage is very cheap, text files are very small, most SVM-s store deltas which are marginal in size and speed.
Agile practices also explicitly include this. Besides source code and project files, consider build, deploy scripts, database schemas and mocks, configurations, documentation(!), test files, dependent libraries, todos, the project's website... Of course sometimes it is difficult to put for example a virtual machine image under version control (binary), regular snapshots might be more applicable for that. But if you ever asks yourself, should I put this under version control, the answer is almost always yes, you should. (Following this practice makes it also easier to make decisions about versioning.)
Everything needed to build and run the project from scratch.
Make sure to add your lib directory also. I absolutely HATE IT when I pull stuff from version control and all of the dependent jar files are no where to be found, causing me to keep guessing until I resolve all the ClassNotFound exceptions. Don't add your build directory or your Netbeans build script unless you are tied down to only running Netbeans. Another alternative is to add a (non-Netbeans) build script.
精彩评论