
Obtaining the NetBeans source code
The source code for NetBeans itself is available under the Common Development and Distribution License (CDDL) v1.0 and GNU General Public License (GPL) v2.
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.
Downloading a zipped archive of the NetBeans source code
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:

Cloning the NetBeans source code from Mercurial
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
If this is your first check out of a branch, Mercurial may take a long time to clone the repository. Depending on your computer and network connection, this may take several hours.
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 clone
operation:
hg --debug clone http://hg.netbeans.org/main-silver/

After cloning the NetBeans source files from the Mercurial repository, we have many subdirectories within the main-silver
directory, as shown in the following screenshot:

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 view any of these tagged releases, simply check out the releases branch and then change to the specified folder for the requested release.
Cloning the NetBeans source code from within NetBeans
To enable us to use Mercurial from within NetBeans, we must first ensure that NetBeans is configured with the location of the Mercurial executable—hg.exe
on Windows and hg
on Mac OS X and Linux.
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 thehg
executable 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
http://hg.netbeans.org/main-silver
. - 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.
Browsing the NetBeans source code online
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:
