Labels
NetBeans is an Integrated Development Environment (IDE), a software package which can be used to develop programs. Several developers use NetBeans to develop GeoTools itself or GeoTools based software. NetBeans is available from Sun Microsystems as a free software download. There are also derivatives such as Sun ONE Studio (previously Forte for J).
These instructions refer to recent versions of Netbeans. If you are using an older version consider upgrading because the new versions offer better support for Maven and Subversion, both valuable for GeoTools programming, as well as many general improvements and bug fixes.
- Installation
- Creating a new project for a GeoTools application
- Using Subversion within Netbeans to get GeoTools source code
- GeoTools javadocs within Netbeans
- Related links
Installation
Install NetBeans
You can install NetBeans in several different ways depending on what operating system you use. If your operating system allows you a standard system to install software packages, such as the package managers available in all free software operating systems, you should use your package manager to install NetBeans.
Alternatively, you can install NetBeans directlyto any directory where you have write permission. The software is available at [www.netbeans.org] which also has instructions to install the software on most major operating systems.
In July 2008, the current version is NetBeans 6.1.
Install the MavenIDE plugin
If you have just installed NetBeans 6 the first thing to do is to add the MevenIDE plugin which gives Netbeans the ability to natively open Maven projects and create new Maven projects as well as other useful bits such as local and remote repository browsing. Installing the plugin is easy. Launch Netbeans, select the Tools menu and then the Plugin item (at the bottom of the menu). This will display the Plugins dialog. Select the Available Plugins tab and you will see Maven listed as one of the Java category plugins. Click the checkbox for Maven and the Install button at the bottom of the dialog. You will be prompted to confirm a licence agreement after which the Maven plugin will be installed.
The Maven plugin includes an embedded version of maven itself so there is no need to install maven separately on your system unless you want to be able to use it from the command line or work with a version different to that included in the Maven plugin. If you do maven separately installed you can choose to use it, rather than the plugin's version, for all projects or for selected projects. To use maven for all projects open the Options dialog by selecting the Preferences item from the Netbeans menu. In the dialog select the Miscellaneous icon at the top, and then the Maven 2 tab below that. Here you can specify the path to your external maven executable and choose to use it for all projects. This is also where you can specify the path to your local maven repository (the directory structure where maven will install copies of all jars and other files required for building projects etc). If you leave the path blank in the Options dialog, a default path will be used (e.g. on unix systems this is ~/.m2/repository).
The Subversion plugin.
You don't have to install a Subversion plugin manually. It comes as part of the Netbeans base IDE.
Specifying and monitoring memory usage
Netbeans is itself a Java application. It automagically sets the amount of memory (heap) that will be available to the Java runtime when it is starting, but you may find that this default size is not large enough. If you get out of memory errors, or if Netbeans seems very sluggish, you can explicitly set the maximum heap size in the file etc/netbeans.conf by adding -J-XmxNb (where N is an integer number of Mb) to the 'netbeans_default_options' variable near the top of the file. For example, here we are requesting a maximum heap size of 640Mb:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Xmx640m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Xverify:none "
Within the IDE you can display current and peak memory usage in a toolbar widget as shown below. To display this: View menu -> Toolbars menu -> Memory

You can force the garbage collector to try to recover memory by clicking on the memory widget.
Creating a new project for a GeoTools application
From the File menu, select New Project. In the New Project dialog choose Maven from the Categories list. In the Projects list you have the choice of Maven Project, which is where you are starting from scratch, or Maven Project with existing POM. This latter option is actually redundant and will just lead you to a message saying that you can open a project with an existing POM with File -> Open Project.

Click the Next button and you will see the Maven Archetype page. An archetype is like a basic template specifying a type of project.

If you are working with GeoTools 2.5 there is a GeoTools Archetype available. If this is your first GeoTools / Netbeans project you can install the GeoTools Archetype onto your system by clicking the Add button at the right to display this dialog below. Fill in the details as shown, specifying the version required (e.g. 2.5-SNAPSHOT) and click the OK button to install the archetype. Note, you will need to be online to download the archetype from a remote repository as shown below.

Back on the previous dialog, make sure that the GeoTools archetype is selected in the listj and click the Next button to display the final dialog (below) where you specify your application's name, directory, root package name etc.

Make sure that you are onlline and then click the Finish button to create the project's directory structure and essential files, including the POM.xml file. If you haven't used maven before this will take some time, depending on your internet connection's speed. Maven will download a reasonably large number of files and install them into the local repository on your system. Once this proecess is completed you should see a "BUILD SUCCESSFUL" message in the Netbeans Output window.
Using Subversion within Netbeans to get GeoTools source code
While it is not necessary for you to have a local copy of the GeoTools source code to build your own apps, it can still be useful to access it. For example, browsing the code can complement reading of the javadocs in helping you to better understand how GeoTools works (or perhaps why it isn't working for you !). You may also want to copy or adapt parts of the demo programs for use in your own apps. In addition to downloading the entire source distribution from the downloads page you can selectively access the source from the GeoTools subversion repository.
Netbeans functions as a subversion client and is very easy to use. To begin. select Subversion in the Versioning menu...

In the Checkout dialog enter the URL for the GeoTools repository as shown below then click the Next button. You can download the code using 'anonymous' access so there is no need to enter username or password.

On the next dialog page you specify the repository path containing the files that you want to check out and the local path for you working copy. To access the source code for different versions of GeoTools click the Browse button next to the Repository Folder(s) text field...

To access the code for the current development version of GeoTools go to the Trunk folder. Other version of GeoTools can be found in the Tags folder. For any version you can selectively download parts of the source, such as in the example shown here where we are selecting the demo folder within GeoTools version 2.4.4.

Once you have specified the source to check out, and the path for your local copy, click the Finish button on the Checkout dialog to commence downloading. You can follow the progress of the download in the Netbeans Output window.
GeoTools javadocs within Netbeans
If you install the GeoTools javadocs into your local maven repository they will be available when you are editing code in the IDE. Here is one way to install the javadocs:
- Download the javadocs for your version of GeoTools from the downloads page.
- Unzip the downloaded file. It will expand into a directory tree with the top directory called apidocs.
- In a command shell, go to the directory containing the apidocs dir and create a jar file:
jar -cf gt2-javadoc.jar apidocs
- In your local maven repository, create a directory called javadoc.jars in the geotools group. For example on a unix or similar system:
cd myhomedir/.m2/repository/org/geotools mkdir javadoc.jars
- Copy the jar file that you created in step 3 into the org/geotools/javadoc.jars directory in the repository.
Related links
Netbeans.org
An article on using Maven within Netbeans
Website for the Maven 2 plugin for Netbeans