views:

251

answers:

5

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 project 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.

+1  A: 

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.

Chandru
Ne careful when working in a heterogenous environment with this. Like Developer A is on Mac and Developer B is on Windows. This might cause some trouble.
er4z0r
sharing metadata can be handy, but it can also be a pain when someone changes their personal settings and everyone on the team gets them
matt b
So... can I leave the entire build/ directory out then? And what are the Ant files that I should add? build.xml?
Makis
Not a good idea to add build.xml, as it imports a Netbeans specific nbproject/build-impl.xml to do the actual build.
GreenieMeanie
A: 

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

sibidiba
Don't put things that are generated by your build process into the SOURCE CODE repository. It just makes it harder for other folks to check out and build the project. Check completed builds into a different location.
Chris Nava
+2  A: 

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

Robin
A: 

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.

GreenieMeanie
+2  A: 

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
vkraemer
Excellent answer and exactly what I was looking for. I'm using git so I have to see if your tip works with it. Having said that, I prefer to do this by hand, but starting with the Import part sounds like a good idea.
Makis
NB does not have support for git 'out of the box'... You will probably want to look at this plugin (http://code.google.com/p/nbgit/) to see if it will be useful.
vkraemer
I had that installed on one computer already and just installed it on this one and it looks like that function is available with git as well.
Makis