It’s possible to obtain the source for NetBeans either as a
.zip file, containing the entire source for a specific release, by cloning the code from the NetBeans Mercurial repository or by viewing the files from within a browser.
If you just want to look at the NetBeans source code and aren’t interested in making changes, you can download the source as a
.zip archive from the relevant download page for any release. At the bottom of each download page, there is a link to download the source in the ZIP file format, as shown in the following screenshot:
The alternative to downloading a ZIP archive of the NetBeans source code is to clone the code from the NetBeans Mercurial repository. To perform this operation, you must have the Mercurial client installed on your computer. It can be downloaded for Windows and Mac OS X. For Linux and Mac OS X, it can be installed via the operating system’s appropriate package manager, for example,
apt-get on Ubuntu or
yum install on Fedora. The Mercurial site at http://mercurial.selenic.com provides all the details on how to install Mercurial.
The NetBeans source code can be cloned from Mercurial from either the command line or from within NetBeans. Let’s first look at how to achieve this using the command line.
Having installed Mercurial, we are in a good position to clone the NetBeans source code using the
hg clone operation.
The NetBeans source code is stored within several branches and tags in the Mercurial repository. The main development for the next version of NetBeans is performed within the
main-silver branch. This branch contains the latest development that has been picked up by the latest automatic stable build of NetBeans.
To check out this branch, execute the following command from within a terminal or command prompt:
hg clone http://hg.netbeans.org/main-silver
Due to the way Mercurial works, hidden files are created on the local filesystem during the first phase of a Mercurial
clone operation. No console output is provided during the checkout phase either, so it may appear that the
clone operation is not working correctly as there is no visible feedback that the sources are being cloned.
It’s possible to tell Mercurial to output status information so that you can see that all is working correctly. This can be especially useful on the first clone of a branch, which can be a lengthy operation. To clone a branch and get status updates output to the console, we must add the
--debug parameter onto the
hg --debug clone http://hg.netbeans.org/main-silver/
In the previous section, we showed how to clone the
main-silver branch from the NetBeans Mercurial repository. What if we don’t want the latest cutting edge development, but want to look at the source code for a specific version of NetBeans?
Fortunately, each release of NetBeans has the source code tagged in the Mercurial repository, so it’s possible to check out any older release going back to December 1999 (this is the first tagged release within Mercurial).
The complete list of tagged releases is available at http://hg.netbeans.org/releases/tags, as shown in the following screenshot:
To configure Mercurial within NetBeans, perform the following steps:
- Open the NetBeans Options dialog. On Windows and Linux, this is achieved by selecting Tools and then Options from the main menu. On Mac OS X, clicking on NetBeans and then Preferences from the application menu opens the Options dialog.
- In the Options dialog, click on the Team option and then choose the Versioning tab.
- On the Versioning tab, ensure that the Mercurial Executable Path field is set as appropriate for your operating system. In the preceding screenshot, you can see that it is set to
/usr/local/bin, which is the folder that contains the
hgexecutable on my computer.
Once we’ve configured the Mercurial support within NetBeans, we can clone the source code repository by performing the following steps:
- Open the Clone External Repository wizard by clicking on Team and then Mercurial and eventually, Clone Other… from the application menu.
- Enter the repository URL as
- Continue on through the wizard until the Destination Directory stage is displayed. On this page, enter the parent directory into which the NetBeans source code will be cloned and ensure that the Scan for NetBeans Projects after Clone option is checked. With this option checked, NetBeans will automatically open the cloned project after the repository is cloned.
- Click on the Finish button to commence the cloning process.
Cloning the NetBeans source code in this way via NetBeans does not provide any visual feedback on the progress of the cloning operation. If you wish to see visual feedback so that you know something is happening, consider cloning the repository via the command line, as described earlier.
The NetBeans source code is available to browse online at http://hg.netbeans.org/main/file. Viewing the source code this way can be very useful for the casual observer who wants to see how something is done within the NetBeans source code, but does not want to download the entire source code to their computer.
The following screenshot shows the top level of the NetBeans source code in a browser window: