Section 10.2. NetBeans: The Open Source IDE


10.2. NetBeans: The Open Source IDE

NetBeans is an Open Source IDE, freely available, with full source code. It is also the basis for the SunONE Studio (more on that product later).

10.2.1. A Brief History of NetBeans[1]

[1] From the netbeans.org Web site.

NetBeans (originally called Xelfi) began in 1996 as a student project in the Czech Republic, with the goal being to write a Delphi-like Java IDE in Java. A company called NetBeans was formed around this project. By May of 1999, after two commercial releases of Developer, the company released a beta of what was to be Developer 3.0. In October 1999 NetBeans was acquired by Sun Microsystems. After some additional development, Sun released the Forte for Java Community Edition IDEthe same IDE that had been in beta as NetBeans Developer 3.0. There had always been interest in going Open Source at NetBeans. In June 2000, Sun open-sourced the NetBeans IDE; now it can be found at the netbeans.org Web site.

10.2.2. Installing NetBeans

NetBeans can be downloaded from the netbeans.org Web site. You will want the NetBeans "IDE" and not the NetBeans "platform." The IDE is the fully featured Java development environment. The platform is the underlying core of NetBeans on top of which one can develop other toolsfor example, IDEs for other languages. Installation of the IDE consists of only three steps:

1.

Download.

2.

Install.

3.

Execute.

10.2.2.1 Downloading

The first step is to get the software downloaded onto your system. From the netbeans.org Web site, navigate your way to a download of the latest IDE. The prepackaged "installers" might workbut if they fail, you have no information as to why, and still less as to what you can do about it. We'll act like "real programmers" and download an archive file. (Here "archive" means a collection of software compressed for easier transmission, not "archive" in the sense of "old documents.") Click on a link to begin the download (you'll need to read, review, and accept the license agreement to proceed). The result should be a file on your system named something like NetBeansIDE-release35.tar.bz2.

10.2.2.2 Installing

The installation consists of three steps: untarring the file, adjusting a parameter in a configuration file, then creating a symbolic link for easy startup.[2]

[2] Thanks to John Zoetebier from New Zealand for his contribution on the NetBeans users mailing list, on which this manual installation procedure is based.

Uncompress the archive:

 bunzip2 NetBeansIDE-release35.tar.bz2 

This will leave the file NetBeansIDE-release35.tar in place of the .bz2 file.

You can examine the contents of the TAR file with:

 tar -tvf NetBeansIDE-release35.tar | more 

Here the options (-tvf) specify to show a table of contents (-t) in verbose, that is, long, form (-v) from the specified file (-f) followed by the TAR filename. The output from tar here is piped into more so that you can page through it. Type q when you've seen enough, or leave off the | more to let it run through without pausing.

Notice that the names of all the files in the TAR archive begin with netbeans/ which tells us that if we untar the file, it will put all the files into a directory called netbeans. Therefore, we don't need to make such a folder beforehand.

Change directory to the directory where you would like to install NetBeans. If you are on a system that may be used by different users, you'll probably want to put it in a more public location like /usr/local or /opt. If it is for your personal use, you can put it anywherejust be sure that you have write permissions on the directory where you want to install NetBeans. (Reminder: use ls -ld . to see the permissions of the current directory.)

The tar command to untar everything in place is simple:

 tar -xf NetBeansIDE-release35.tar 

This will extract (-x) all the files that are in the TAR file (-f) named NetBeansIDE-release35.tar. If you'd like to see each file get named as it is extracted, then change the -xf to -xvf (v for verbose) and you will see a whole long list of filenames displayed on your screen as the file is unpacked.

Next, we need to adjust the startup parameter in the configuration file. The file is in the netbeans directory that you just untarred. In there is a directory named bin, and in there is a file called ide.cfg. Open this file with an editor and change the line that begins -jdkhome so that the pathname refers to the location of your Java Development Kit (JDK, see Chapter 5).

Here's an example of the contents of ide.cfg:

 -J-Xms24m -J-Xmx96m -J-Xverify:none -jdkhome /usr/local/java/j2sdk1.4.1_01 

This specifies that the Java SDK is located in /usr/local/java/j2sdk1.4.1_01, and in that directory there is a bin directory which contains java, javac, javadoc, and so on.

Finally, to make the executable easy to run, we will construct a symbolic link for easy access:

 $ ln -s /usr/local/netbeans/bin/runide.sh /usr/local/bin/nb 

This creates a symbolic link from the runide.sh file in the current directory to the /usr/local/bin directory, as a file named nb.

10.2.2.3 Running

Now that you have the symbolic link to the script which runs NetBeans, simply invoke it with nb at a shell prompt. NetBeans will start loading (Figure 10.1).

Figure 10.1. NetBeans begins


If you get a message like "Command not found," check to see if the shell knows where to look. If you used the same name and location as in the previous example, then make sure that /usr/local/bin is part of the search path for the shell. (Reminder: echo $PATH will tell you what directories are searched. If you need to, add /usr/local/bin to PATH, as in:

 export PATH="${PATH}:/usr/local/bin" 

which you can type from the command line for immediate use and then put in the .bashrc file in your home directory to set things this way next time you invoke a shell.)

Also be sure that the script runide.sh has execute permissions on it. (Reminder: check this with ls -l runide.sh and change with chmod a+x runide.sh.)

If all goes well then after the splash screen, you should see the window shown in Figure 10.2.

Figure 10.2. NetBeans' main window


For more information on installing NetBeans, check out http://www.netbeans.org/kb/articles/install.html#unix.

Now let's take a look at how you might use NetBeans.

10.2.3. Getting Around in NetBeans

Let's take a look, from top down, at NetBeans' main window. First, of course, is the menu bar. There are lots of choices to explore there. Much of what you'll do with NetBeans won't require much use of the menusthere are so many shortcuts elsewhere.

Next comes a row of icons, which are just shortcuts for menu times. This row of icons can be customized, and you can even add your own (see Section 10.2.5).

The three tabs below the icons, labeled Editing, GUI Editing, and Debugging, modify the window to provide three distinct workspaces. Each one customizes the window environment for a specific task, but it is still working on the same files.

Next, on the left, comes the Explorer, which is in many ways similar to the tools that you may use for traversing filesystems on a Windows or Linux system.

One oddity of NetBeans is that it doesn't just use the files as it finds them in the directories on your hard drive(s). Rather, is requires you to designate a piece of the filesystem as the part that you want to use. You can designate several such pieces. Each piece is "mounted" as if it were a mountable filesystem. (This is an operating system concept. If you're not familiar with it, don't worry. For the purposes of NetBeans, just think of the IDE as too dumb to know about any files until you tell it about them.)

There are three different types of files that you can mountlocal, CVS, or JAR. By specifying the type, NetBeans can treat each one in its special way.

  • Local files need no special treatment; they are just the local files on your hard drive.

  • If a filesystem is mounted under a version control system (CVS or generic VCS), then its files can have version control operations performed on them (checkin, checkout, and so on), via commands in the IDE. (More on that below.) Also, special directories used by the version control system (e.g., CVS) are hidden from the display, as you almost never want to manipulate these files directly.

  • When you mount a JAR file or ZIP archive as a filesystem, NetBeans displays the contents of the archive as if they were just files in a directorywhich can make them easier to manipulate. More importantly, the JAR is automatically added to the classpath for Java compiling. Therefore, any third-party JARs that you may need for your project should be mounted.

To mount a local directory as a filesystem, right-click on the little icon labeled Filesystems in the Explorer [Filesystems] window. Choose Mount, then Local Directory, and you'll get a filechooser to let you navigate your file structure and choose a directory to mount.

Important

To ensure that NetBeans knows how to compile your source, you need to mount the directory that contains the base level of your source as a mountpoint, not just have that directory somewhere in a tree of directories.

For example, let's say that your source is kept in two packages, com.coolco.projecta and com.coolco.util which implies that you have a directory structure with those names. Let's further assume that you keep them in a directory called src which is itself contained in a directory called brolly, as shown in Figure 10.3.

Figure 10.3. A simple source structure


The likely thing to do is to mount the brolly directory, since it will contain the source and all sorts of other project-related directories. That's fine, as far as it goes. But since the mountpoints in NetBeans are also the CLASSPATH directories, you need to also mount brolly/src, so that directories like com/coolco/util are found when your Java sources have statements such as import com.coolco.util.*;.

It's OK to have the same directory show up in different mountpoints. NetBeans won't get confused, although you may. You'll probably want to edit and compile from the mountpoint of, in this example, brolly/src. The src folder inside the brolly mountpoint would refer to the same files. Just keep the one always open and the other closed, and you should be able to keep them straight.


10.2.3.1 Filesystem versus Project

The Explorer window has tabs at the bottom which let you look at different aspects of your work. In some instances you'll want the Project view. For this, you have to mount file's from the already mounted filesystems in the Filesystem view. Seems redundant, no? The Project view lets you set properties for the project as a whole or for individual files in the project. These settings apply to that file only for the project. Another project, looking at the same files, might have different settings.

For now, don't worry about the difference. Many people like to work in the Filesystem view and never bother with projects. Others, especially those working on multiple products or projects, like Projects as a way to switch between tasksyou can only have one project active at a time, but when you switch projects, it switches all the mounted filesystems and other settings that you have configured.

10.2.3.2 Editing

Like other IDEs, NetBeans provides its own editing window. It's a GUI point-and-click environment, with syntax highlighting and other helpful features for a programmer.

At the top of the editing window is a toolbar (Figure 10.4). Each icon on the toolbar has a tooltip, a help text that pops up when you rest your mouse pointer over the icon, to explain the somewhat cryptic little icons. Most of the tools are quite handy. With the pulldown menu, you can navigate to any method or class variable within the class. The next four buttons deal with searching: Select any text in your source file, click on the magnifying glass icon, and the search will be performed for the next occurrence of that text. In addition, all occurrences are highlighted. This highlighting can be toggled on or off.

Figure 10.4. NetBeans' Edit screen toolbar


The toolbar search only works within a single source file. If you want to search across multiple files, go back to the Explorer window and right-click on the folder containing the files you wish to search. There is a Find ... command in the pop-up menu. That brings up a dialog box (Figure 10.5) that has multiple tabs for quite extensive filtering of your search. In its simplest use, just type in the text you want to find, and press Enter.

Figure 10.5. NetBeans' Find dialog


A list of the files which contain the text will appear in a different window, citing filename and linenumber for each file. There you can double-click on any citation to bring up that file in the edit window, at that location.

If you heeded our admonition to learn vi, you'll be glad to know that NetBeans can handle the fact that the source files can be modified externally from the IDE. Go ahead and edit any of your source files, even while the IDE is running. When you next touch the file from within the IDE, NetBeans will recognize the fact that the file has been modified and load the new version.

If you haven't yet learned vi, you may find yourself quite comfortable using the NetBeans editor. If you dig deeper into NetBeans you can find how to map certain keystrokes to make it even more editor-like. However, mousing and cut-and-paste may suffice for beginners for quite some time.

10.2.4. Integration with CVS

NetBeans comes with a built-in CVS client, which means that you don't need to install any additional features in NetBeans to get it to talk with a CVS server. It has all it needs to check out and commit files from and to a CVS repository. NetBeans can be configured to use external (i.e., outside of NetBeans) CVS commands, but you likely won't need to do that.

What you will need to do, however, is tell NetBeans that the files you are using are under CVS control. You do this by mounting the filesystem not as just a regular filesystem, but as a CVS filesystem. In the Explorer window, go to the Filesystem tab if you are not already there. On the Filesystem icon, right-click your mouse, and from the pulldown menu choose Mount, then Version Control, then CVS (Figure 10.6). What follows will be a wizard-like series of dialogs which you will fill in to describe the type and location of the CVS repository with which you want to work. Those choices and values are specific to your installation, so we'll leave that for you to figure out with your network administrator or whoever has set up your repository.

Figure 10.6. Mounting a CVS filesystem


Once mounted, the CVS filesystem's files will look much like any other filesystem you have mountedexcept that the files will show, via their icon, when they have been modified and need to be committed, and will show the version number in parentheses after the filename. The other difference is that there is now a CVS command on the pulldown menu (Figure 10.7) that appears when you right-click on one of the filenames (or on its tab in the Edit view).

Figure 10.7. Right click on a CVS file


Move your mouse over the CVS command; an additional pulldown menu appears (Figure 10.8). If you've used CVS at all, then you'll recognize the list of commands in the cascaded menu. There are the Commit, Update, Diff, Log, Status, and Checkout commands that you are familiar with. The first item, Refresh, is likely unfamiliar, though. Not being a CVS command (it's not part of the command-line syntax), it is a way for you to tell the IDE to reconsider what it thinks about the CVS-related information displayed in its icons and the parenthetical text.

Figure 10.8. Cascaded menu with CVS commands


If you click on a folder instead of a single file, then the Refresh command will be followed by Refresh Recursively which will do a refresh on each file from there on down the tree.

Using the integrated CVS is much like using the command line. If you want to see the changes that you've made (before committing), use the Diff command. A window will appear showing the two different versions and coloring the lines that have been added, deleted, or changed.

When you need to commit your changes, click the filename, then right-mouse your way to Commit. A dialog window will appear for you to type in the comment that you want to be associated with this change. (This comment will appear in the Log command display).

To incorporate the changes others on your project may have made on the file, use the Update command. A dialog box will display the CVS output showing what was updated and if any merge conflicts occurred. (See Chapter 8 for more on this.)

The CVS commands in the menu, as we've described them so far, don't allow you to add any options to the commands. They just run with the defaults. What if you want to use some of the options available on the CVS command line? Then hold down the Ctrl key just before your make your CVS choices. You should see an ellipsis ("...") appear after each CVS command for which you can now select options (Figure 10.9).

Figure 10.9. Cascaded menu after choosing CVS with Ctrl pressed


Of course one of the great things about knowing the command-line version (see Chapter 8) is that you're not limited to what the GUI tools will do for you. If you can't find the option you want, just go back to a window with a shell prompt, cd into the appropriate directory in your source tree, and type the CVS command by hand. As noted earlier, NetBeans is smart enough to catch on to the changes made outside of NetBeans to its files, though you may need to do a Refresh, as described above.

10.2.5. Integration with Ant

If you've already discovered ant, either by using it on a Java project or by reading this book in chapter order, then you'll know that it's a plus to have ant integrated into NetBeans. As of NetBeans version 3.5, ant comes bundled with NetBeans and you don't need to install it separately.

NetBeans recognizes a build.xml buildfile and gives it a special icon. If you click on the icon for the build.xml file in the Explorer, it will show each of the properties and then each of the targets (Figure 10.10). Right-click on a target to choose Execute to run ant with that target. As a shortcut you can either select that target and press the F6 key, or you can just double-click on the target name.

Figure 10.10. Cascaded menu after choosing CVS


If you are making frequent use of an ant build script in your project, you may want to add a shortcutan icon that you can put on the icon panelthat will run a specified ant target. You can also add a keyboard shortcut, to invoke the target with a keystroke or two. The specific steps for doing that are found in the NetBeans online help. Just look for the section titled Creating a Shortcut to a Target.

There is one other topic worth mentioning about integration with ant. Normally in NetBeans, when you compile a Java class, the IDE does the compilation. You can configure the IDE to use different types and versions of Java compiler, but it is the IDE which controls the compile. You can invoke a compile with the F9 key as a shortcut. But if you are building with ant, you may want ant to do the compiles for you. Fortunately, you can configure NetBeans to do this. Again, we'll refer you to the NetBeans online help, to a section called Indirect Ant Compilation.

10.2.6. Other Add-on Tools

NetBeans is built to allow other tools to be plugged into it. There is a module that you can add to NetBeans to support C/C++ development. But there are various other plug-ins available. The best reference for all of those is the NetBeans Web site.[3] Many of the add-ons are commercial, but one notable tool is available, at least in its simple form, as a free download.

[3] http://www.netbeans.org/about/third-party.html

Poseidon for UML Community Edition is a UML modeling tool that integrates with NetBeans. A product of Gentleware AG, it is distributed at their Web site.[4] The Community Edition is offered free of charge, but they have more advanced (professional, enterprise) versions for sale. Their Web site says that Poseidon for UML Community Edition has the following features:

[4] http://www.gentleware.com/

  • Fully implemented in Java, platform-independent

  • All 9 diagrams of the UML supported

  • Compliant to the UML 1.4 standard

  • XMI supported as standard saving format

  • Runs under Java 1.4

  • Diagram export into GIF, PS, EPS, SVG, JPEG, and PNG

  • Undo/redo (can be turned on in options)

  • Copy/cut/paste within the tool

  • Drag and drop within the tool

  • Zooming and bird's eye view of the diagrams

  • Internationalization and localization for English, German, French, and Spanish

  • Code generation for Java

  • Sophisticated support of OCL

  • Reverse engineering from Java sources

  • Auto-layout of reverse engineered diagrams

  • Cognitive support, critique mechanism (by default turned off)

  • Simple install and update with JavaWebStart

We won't be discussing its installation or use, but we encourage you to explore this option if you need a UML tool.



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net