UsingNetBeans4 0 PDF
UsingNetBeans4 0 PDF
0
Your Guide to Getting Work Done in NetBeans IDE
Welcome to the Using NetBeansTM IDE 4.0 guide. This guide is designed to give you a more
detailed introduction to the IDE than available in the Quick Start tutorials. The main aspects of
the IDE are explored in detail.
This guide is geared mostly to newcomers to NetBeans IDE 4.0, whether they are new to using
IDEs or experienced IDE users that are switching over from a different IDE. However, readers of
this guide are assumed to have at least a basic understanding of the Java programming language
and related technologies.
Setting Up Projects
This section covers the basics of setting up your IDE to start developing your projects. The
process of managing project contents and properties is centered around the Projects window.
The most common tasks in setting up a project are creating a project, setting the target JDK in a
project, and making resource libraries available to the project.
Before you start setting up your project, let's take a minute to get acquainted with some of the
basic concepts involved with using the IDE.
Projects
An IDE project is a group of Java source files and its associated information about what belongs
on the classpath, how to build and run the project, and so forth. The IDE stores project
information in a project folder which includes an Ant build script and properties file that control
the build and run settings, and a project.xml file that maps Ant targets to IDE commands. Your
source directories do not need to be located in the project folder. In the IDE, you always work
inside of a project. You can create standard projects that use an IDE-generated Ant script to
build the project, or create free-form projects that are based on your existing Ant scripts.
The following table summarizes the major differences between standard projects and free-form
projects:
● Java Application. Template for creating a skeleton J2SE project with a main class.
● Java Class Library. Template for creating a skeleton Java class library without a main
class.
● Web Application. Template for creating a skeleton web application.
● Java Project with Existing Sources. Template for creating a J2SE project based on
your own Java sources.
● Web Project with Existing Sources. Template for creating a web project based on
your own web and Java sources.
● Java Project with Existing Ant Script. Template for creating a J2SE project based
on your own Java sources, built using your own Ant build script.
● Web Project with Existing Ant Script. Template for creating a web project based on
your own web and Java sources, built using your own Ant build script.
Ant
Apache Ant is a Java-based build tool used to standardize and automate build and run
environments for development. The IDE's project system is built directly on top of Ant. All of the
project commands, like Build Project or Run File in Debugger, call targets in the project's Ant
script. You can therefore build and run your project outside the IDE exactly as it is built and run
inside the IDE.
You do not need to know Ant to work with the IDE. You can set all the basic compilation and
runtime options in the project's Project Properties dialog box and the IDE automatically updates
your project's Ant script. If you know how to work with Ant, you can customize a standard
project's Ant script or write your own Ant script for your project.
Creating a Project
When you finish creating a project, it opens in the IDE. You can view its logical structure in the
Projects window and its file structure in the Files window:
● The Projects window is the main entry point to your project sources. It shows a logical
view of important project contents such as Java packages and Web pages. You can right-
click any project node to access a contextual menu of commands for building, running,
and debugging the project, as well as opening the Project Properties dialog box. You can
open the Projects window by choosing Window > Projects (Ctrl-1).
● The Files window shows a directory-based view of your projects, including files and folders
that are not displayed in the Projects Window. From the Files window, you can open and
edit your project configuration files, like the project build script and properties file. You can
also view build outputs like compiled classes, JAR files, WAR files, and generated Javadoc
documentation. You can open the Files window by choosing Window > Files (Ctrl-2).
In addition, the Favorites window lets you access any location on your computer. This is handy
for accessing files and directories that are outside of your project directories. The Favorites
window does not know anything about project classpath and membership, so none of the project-
related commands like Compile File are available in the Favorites window. You can open the
Favorites window by choosing Window > Favorites (Ctrl-3).
When you develop a large application consisting of numerous source folders, it is common to split
up your code into separate projects. Of these projects, one is typically the entry point for your
application and, if it is a J2SE application, contains the application's main class. To tell the IDE
which of your projects is the main entry point for your application, you set one project to be the
main project. The IDE provides commands that act on the main project. For example, running
the Build Main Project command builds both the main project and all of its required projects,
thereby ensuring that all of your compiled classes are up-to-date. To set a project as the main
project, right-click the project node in the Projects window, and choose Set as Main Project. Only
one project can be the main project at any time.
You can run the IDE with a different JDK version by starting the IDE with the --jdkhome jdk-
home-dir switch on the command line or in your IDE-HOME/etc/netbeans.conf file. For more
information, see Configuring IDE Startup Switches.
In the IDE, you can register multiple Java platforms and attach Javadoc and source code to each
platform. Switching the target JDK for a standard project does the following:
In standard projects, you can switch the target JDK in the General page of the Project Properties
dialog box. In free-form projects, you have to set the target JDK in the Ant script itself, then
specify the source level in the Sources page of the Project Properties dialog box.
To register a new Java platform, choose Tools > Java Platform Manager from the main window.
Specify the directory that contains the Java platform as well as the sources and Javadoc needed
for debugging.
Adding a group of class files to a project's classpath tells the IDE which classes the project should
have access to during compilation and execution. The IDE also uses classpath settings to enable
code completion, automatic highlighting of compilation errors, and refactoring. For both standard
projects and free-form projects, you first declare the classpath in the New Project wizard when
creating the project. You can edit all classpath declarations for an existing project in the Project
Properties dialog box, as explained below.
● In standard projects, the IDE maintains separate classpaths for compiling and running
your project, as well as compiling and running JUnit tests (for J2SE applications). The IDE
automatically adds everything on your project's compilation classpath to the project's
runtime classpath. Right-click the standard project's node in the Projects window and
choose Properties. Click Compiling Sources and add JAR files, libraries, and projects to the
project's compilation classpath.
● In free-form projects, your Ant script handles the classpath for all of your source folders.
The classpath settings for free-form projects only tell the IDE what classes to make
available for code completion and refactoring. Right-click the project node to access the
Project Properties dialog box, click Classpath and then declare the classpath for the
project.
In free-form projects, note that declaring the classpath in the Project Properties dialog box
does not change the actual compilation or runtime classpath of the source folders. The
project's classpath declaration must exactly match the classpath used by your Ant script.
If you have attached Javadoc and source files to a JAR file in the Library Manager, the IDE
automatically adds the Javadoc and source files to the project when you register the JAR file on a
project's classpath. You can step into classes and look up Javadoc pages for the classes without
configuring anything else.
When you create separate standard projects for each of your source roots, you have to set up
the classpath dependencies between the projects. Typically you set up one main project,
containing the project main class (in J2SE projects), and several required projects. A required
project is a project that has been added to another project's classpath. When you clean and build
a project, the IDE also cleans and builds its required projects. The required project's Javadoc and
sources are also made available to the receiving project. Right-click the standard project's node
in the Projects window and choose Properties. Click Compiling Sources, click Add Project, and
select the project folder whose JAR files you want to add to the classpath. The file chooser
displays IDE project folders with a icon. Click Add Project JAR Files and make sure that the
Build Projects on Classpath checkbox is selected.
If you want to add a free-form project to the classpath of a standard project, you have to add
the project's JAR file and then register it have to declare all of the free-form project's output
files. First add the free-form project's JAR file Right-click the free-form project's node in the
Projects window and choose Properties. Then declare the output files in the Output page of the
dialog box.
Creating and Editing Java Source Code
Creating and editing Java source code is the most important function that the IDE serves. After all, that's
probably what you spend most of your day doing. NetBeans IDE provides a wide range of tools that can
compliment any developer's personal style, whether you prefer to code everything by hand or want the IDE to
generate large chunks of code for you.
NetBeans IDE contains templates and wizards that you can use to create all kinds of source files, from Java
source files to XML documents and resource bundles.
Now right-click the project and choose New > Java Class. Name the file ColorPreview and the package Color.
Click Finish. The package is created in the Source Packages folder, the file is created in the package and opens
in the Source Editor.
If you want to visually edit a Java GUI form using the Form Editor, you have to create the form's source file
using the IDE's Java GUI Forms templates. This template group contains templates for AWT and SWING forms.
For example, you cannot create a normal Java class file and then change it to extend JPanel and edit it in the
Form Editor.
The Source Editor is your main tool for editing source code. It provides a wide range of features that make
writing code simpler and quicker, like code completion, highlighting of compilation errors, syntax highlighting of
code elements, and advanced formatting and search features.
Although we talk about the Source Editor as one component, it is really a collection of editors. Each type of
source file has its own editor that provides different functionality. In this section we'll be dealing with the Java
editor, but many of the same concepts apply to other editors.
To open a Java source file in the Source Editor, double-click the file's node in the Projects window or Files
window.
Note: Double-clicking a Java form node ( ) in the Projects window or Files window opens a Form Editor that
has two buttons, one for the design view and one for the source view. To edit the source code for a Java form
without opening the Form Editor, right-click its node and choose Edit from the contextual menu.
The Source Editor provides many features that spare you from having to enter long Java class names and
expressions by hand. The most commonly used of these features are abbreviations, code completion, and word
matching.
You can also add your own custom abbreviations for each type of editor. In the Options window, select Editing >
Editor Settings > Java Editor and open the property editor for the Abbreviations property. You can use the
Abbreviations property editor to add, remove, and edit the abbreviations for Java files.
Word matching is a feature that lets you type a few characters of a word that appears elsewhere in your code
and then have the Source Editor generate the rest of the word. Type a few characters and press Ctrl-L to
generate the next matching word or Ctrl-K to generate the previous matching word.
As a quick exercise, let's make ColorPreview extend JPanel. Put the insertion point after ColorPicker in the
class declaration, then type ex and press the space bar to expand the abbreviation into extends. Then type the
first few letters of javax. The code completion box should pop up after a few seconds. If it does not, you can
always manually open it by pressing Ctrl-Space. Use the code completion box to enter javax.swing.JPanel.
The IDE uses the classes on your compilation classpath to provide suggestions for code completion and other
features. Classes from the target JDK version, other commonly used project-specific APIs like the Servlet, JSP,
JSTL and XML APIs, as well as the sources you have manually added to the classpath can be used in code
completion. For details, see Managing a Project's Classpath.
In the Options window, you can disable and enable code completion and set the length of the pause before the
code completion box appears in the Source Editor. Select Editing > Editor Settings > Java Editor and set the
Auto Popup Completion Window property and the Delay of Completion Window Auto Popup property accordingly.
You can also turn off the Javadoc preview box for code completion. Select Java Editor and uncheck the Auto
Popup Javadoc Window property.
Refactoring
Refactoring is the restructuring of code, using small transformations, where the result does not change any
program behavior. This type of code rewriting has gone on from the beginning of programming, but it did not
get the official name of refactoring until recently. Just as you factor an expression to make it easier to
understand or modify, you refactor code to make it easier to read, simpler to understand, and faster to update.
And just as a refactored expression must produce the same result, the refactored program must be functionally
equivalent with the orginal source.
● Find Usages. Finds where classes, variables, and methods are used throughout the source code in your
project.
● Move. Enables you to move a class to another package or into another class and enables you to move a
static field or a static method from one class to another. In addition, it updates all source code in your
project to reference the element in its new location.
● Rename. Enables you to change the name of a class, variable, or method to something more
meaningful. In addition, it updates all source code in your project to reference the element by its new
name.
● Encapsulate Field. Generates a getter method and and a setter method for a field and optionally
updates all referencing code to access the field using the getter and setter methods.
● Change Method Parameters. Enables you to add parameters to a method and change the access
modifier.
● Undo Refactoring. Enables you to roll back all the changes in all the files that were affected by the
refactoring.
Even if you prefer to write your code the old-fashioned way, the NetBeans IDE Java editor has some cool code
generation features that you may find handy, especially when dealing with bean properties and event listeners.
Let's start by adding some of the fields for our colors in ColorPreview. Go to the first line after the class
declaration and type in the following code:
int red;
Now let's turn this ordinary field into a bean property by making some getter and setter methods for it. Right-
click in the field name and choose Refactor > Encapsulate Fields. Click Next and then click Do Refactoring. The
following code is generated in the file:
The methods now show up under the Methods node. The Bean Patterns node now also contains a bean property
node for red.
Now let's add both the field and the get and set methods at the same time. In the Projects window, right-click
the Bean Patterns node for ColorPreview and choose Add > Property. In the dialog, enter green for the name
and int for the type, then check Generate Field, Generate Get Method, and Generate Set Method and click OK.
The following code is added to the file:
So far, so good. But to fully generate a working bean that can get and set the value of each of the color bean
properties and notify the caller of its changes, we have to add event listeners to each of the set methods. There
are two ways to do this. You could right-click the Bean Patterns node and choose Add > Multicast Event Source
to add the java.beans.propertyChangeListener methods, then enter the rest of the source by hand.
An easier way is to generate all of the necessary code when you create the bean properties. First, let's get rid of
all of the methods and fields we have created so far. You can do so by deleting the nodes from the Projects or
Files window or just by deleting the code in the Source Editor.
Next, right-click the Bean Patterns node and choose Add > Property. Enter red for the name, int for the type,
and select the Bound checkbox. Now you can set the dialog to generate not just the field and methods for the
property, but also the property change support code. Click OK to generate the following code in the Source
Editor:
private int red;
Then all you have to do is repeat the process for the green and blue properties and change the ColorPreview
constructor to the following:
public ColorPreview() {
propertyChangeSupport = new java.beans.PropertyChangeSupport(this);
}
And that's it! You've got a nice working bean ready to be used by the ColorPicker program.
You can add import statements for Java classes in one of these two ways:
● For the whole file, by pressing Alt-Shift-F (Fix Imports) when the insertion point is in the file in the Source
Editor.
● Individually, by pressing Alt-Shift-I (Fast Import) when the insertion point is in the referenced class name
in your code.
Note that the Fix import command does not remove fully-qualified class names from code and replace them with
import statements.
The Fast Import command enables you to choose how you want the import handled in your code. You can:
When you are dealing with a large group of files, the ability to quickly find, navigate to, and select certain
strings or files is critical to your productivity. The following list gives you a quick overview of the search and
selection tools that are available in the Source Editor:
Keyboard Description
Shortcut of Command
Ctrl-F Search for text in the currently selected file. The Source Editor jumps to the first
occurrence of the string and highlights all matching strings. You can use F3 to jump to
the next occurrence and Shift-F3 to jump to the previous.
Shift-F3 Find the previous occurrence of the word you searched for.
Ctrl-F3 Search for the next occurrence of the word that the insertion point is on.
Alt-Shift-O Open the Fast Open dialog box, which lets you quickly open a file. Start typing a class
name in the dialog box. As you type, all files that match the typed prefix are shown.
Alt-O Go to source. This shortcut opens the file where the item at the insertion point is
defined.
Alt-G Go to declaration. Similar to the previous shortcut, this opens the file where the
variable at the insertion point is declared.
Ctrl-G Go to line. Enter any line number for the current file and press Enter to jump to that
line.
Ctrl-F2 Add a bookmark ( ) to the line of code that the insertion point is currently on. If the
line already contains a bookmark, this command removes the bookmark.
Alt-L Go to the next location in the jump list for the currently selected file. The jump list is
a history of all locations where you made modifications in the Editor.
Alt-K Go to the previous location in the jump list for the currently selected file.
Alt-Shift-L Go to the next jump list location in all files (not the currently selected file).
The IDE automatically formats your code as you write it. You can automatically reformat specific lines of code or
entire files. The following table lists some common formatting commands.
Keyboard Description
Shortcut of Command
Ctrl-Shift-F Reformat the entire file or whatever text is selected in the Source Editor.
Ctrl-T Shift the current line or selection one tab to the right.
Ctrl-D Shift the current line or selection one tab to the left.
Ctrl-Shift-T Comment out the current line or all selected lines with line comments ("//").
Ctrl-Shift-D Remove comments. This command only works for lines that begin with line comments
("//").
The Source Editor makes it easy to manage large number of open documents at one time. The Source Editor
displays a row of tabs for open documents. The tabs appear in the order in which you opened the documents.
You can grab any tab and drag it along the row of tabs to move its position. Use the left and right buttons in the
top-right corner to scroll through the row of tabs.
● Use the drop down list at the top-right of Source Editor. The drop down list displays all of your open files
in alphabetical order.
● Press Alt-Left and Alt-Right to move one editor tab to the left or right.
● Press Ctrl-Tab or Ctrl-` to open the IDE window manager, which contains icons for each open document
in the Source Editor as well as all open windows like the Projects window.
● Maximize the Source Editor. Double-click any document tab or press Shift-Escape to hide all other IDE
windows. If you have split the Source Editor, only the partition you maximize is displayed.
● Clone a document. Right-click the document in the Source Editor and choose Clone Document.
● Split the Source Editor. Grabbing any document tab and drag it to the left or bottom margin of the
Source Editor. A red box shows you where the new Source Editor partition will reside once you drop the
document. Any Source Editor partition can also be split any number of times.
● Move documents between Source Editor partitions. Grab the document tab and drag it to the row of
tabs in the destination partition.
To configure Source Editor settings, open the Options window and expand Editing > Editor Settings. The Editor
Settings node has subnodes for the editors used for each different file type. In this section, we will be looking at
configuring the Java editor, but many of the settings are the same for all editors.
Here is a quick overview of some of the more common customizations to the Source Editor:
● View or change abbreviations. Open the property editor for the Abbreviations property and make any
changes to the list.
● View or change all keyboard shortcuts for the IDE. Open the property editor for the Key Bindings
property.
● View or change all recorded macros. Open the property editor for the Key Bindings property.
● Turn off code completion. Set the Auto Popup Completion Window property to False.
● Set the font size and color for code. Use the Font Size property to quickly change the font size for all
Java code in the Source Editor. Open the property editor for Fonts and Colors to change the font and
color of each type of Java code, like method names or strings.
● Change the indentation used in your code. You can switch between indentation engines by choosing
a new engine from the Indentation Engine property. You can also configure each indentation engine by
opening the property editor for the property.
● Set how many spaces are inserted for each tab in your code. Set the Tab Size property accordingly.
● Turn off Javadoc for code completion. Go to the Expert tab and set the Auto Popup Javadoc Window
to False.
Building Applications
The IDE uses an Ant build script to build your web applications. If you are using a standard project, the IDE generates the build
script based on the options you enter in the New Project wizard and the project's Project Properties dialog box.
If you are using a free-form project, the IDE uses your existing Ant build script. You can write a target that compiles the
currently selected file in the IDE and map it to the Run File command.
To customize the build process for web applications and to redefine WAR files, see Developing Web Applications.
Compilation in the IDE is simple. Make sure that your project's compilation classpath is set correctly. Next, select the project,
package, or file you want to compile and choose the appropriate Build or Compile command. The IDE then compiles the files.
To compile a project, package, or file, select it in the Projects window and choose one of the following from the main window:
● In the main menu, choose Build > Build Main Project (F11) to build the main project.
● In the main menu, choose Build > Clean and Build Main Project (Shift+F11) to clean and build the main project.
● Right-click the project in the Projects window and choose Build Project to build a project.
● Right-click the project in the Projects window and choose Clean Project to clean a project.
● Right-click the package in the Projects window and choose Compile Package (F9) to compile a package.
● Right-click the file in the Projects window and choose Compile File (F9) to compile a file. Alternatively, choose Build >
Compile File (F9). If you are using a free-form project, this command is disabled by default. You have to write an Ant
target for compiling the currently selected file in the IDE and map it to the Compile File command.
In the Files window, expand the project node. In standard projects, the IDE compiles classes to the build folder and builds a
JAR file for Java projects from your project sources. This is done automatically. The JAR file is generated to the dist directory
of your project folder. In free-form projects, your Ant script controls output file creation.
Any compilation errors and output are displayed in the Output window, as described below.
Any compilation errors and output are displayed in the Output Window. The Output window is a multi-tabbed window that
displays messages from the IDE. This window is displayed automatically when you generate compilation errors, debug your
program, generate Javadoc documentation, and so on. You can also open this window by choosing Window > Output (Ctrl-4).
One function of the Output window is to notify you of errors found while compiling your program. The error message is
displayed in blue underlined text and is linked to the line in the source code that caused the error. The Output window also
provides links to errors found when running Ant build scripts.
If the file that contains the error is open, the Source Editor jumps to the line containing each error as you move the insertion
point into the error in the Source Editor. You can also use the F12 and Shift-F12 keyboard shortcuts to move to the next and
previous error in the file.
Every action that is run by an Ant script, such as compiling, running, and debugging files, sends its output to the same Output
window tab. If you need to save some output, you can copy and paste it to a separate file. To set Ant to print the command
output for each new target to a new Output window tab, choose Tools > Options, select Ant Settings, and select the checkbox in
the Reuse Output Tabs property.
With standard projects, you can customize the build process by doing any of the following:
● Enter basic options, like classpath settings and JAR filters, in the New Project wizard when you create a project, or
afterwards in the Project Properties dialog box.
● Customize existing Ant targets in standard projects.
● Create new Ant targets in free-form projects.
● Edit properties in project.properties to change the name and location of build output folders and files.
The following table lists some common tasks for redefining a JAR file:
Specify which files Right-click the project node in the Projects window and choose Properties. Click
are added to a JAR Creating JAR and configure the filter and compression settings. See the Regular
file. Expressions table below for details.
Change a JAR file's In the Files window, go to the nbproject folder in your project folder and open
name and location. project.properties in the Source Editor. Enter the full path to the JAR file in the
dist.jar property.
Specify the manifest In project.properties, type the name of the manifest file in the manifest.file
file for a JAR file. property. The file name must be specified relative to the project's build.xml file.
Note that if you are using the Java Application template, the IDE creates a manifest
file for you.
Disable the In the Files window, open your project folder and open build.xml. Override the jar
generation of a JAR target to have no contents and no dependencies. For example, add the following to
file for a project. build.xml:
To customize the build process for web applications and to redefine WAR files, see Developing Web Applications.
When you create a JAR file or a WAR file, you usually want to include just the compiled .class files and any other resource
files located in your source directory, such as resource bundles or XML documents. The default filter does this for you by
excluding all .java, .nbattrs, and .form files from your output file. Here are some additional regular expressions you can use:
(Key)|(\.gif$) Include all GIF files and any files with Key in their name
The IDE uses an Ant script to run your applications. If you are using a standard project, the IDE
generates the build script based on the options you enter in the project's Project Properties
dialog box. For Java applications, you can set the project's main class, runtime arguments, VM
arguments, and working directory in the Project Properties dialog box.
If you are using a free-form project, the IDE uses your existing Ant script to run your application.
You can write a target that executes the currently selected file in the IDE and map it to the Run
File command.
To set runtime options for web applications, see Developing Web Applications.
You typically set the project that contains the program's main class (for Java projects) as the
main project. For web projects, the main project is the project that is first deployed. You then
run the entire application with the Run Main Project command (F6). You can also run any
runnable class by choosing Run > Run Other > Run File (Shift-F6). You can run any project by
right-clicking its project node in the Projects window and choosing Run Project. For Java projects,
the project must have a main class.
To compile a project, package, or file, select it in the Projects window and choose one of the
following from the main window:
● In the main menu, choose Run > Run Main Project (F6) to run the main project.
● Right-click the project in the Projects window and choose Run Project to run a project.
● Right-click the file in the Projects window and choose Run File (Shift+F6) to run a file.
Alternatively, choose Run > Run Other > Run File (Shift+F6). If you are using a free-
form project, this command is disabled by default. You have to write an Ant target for
running the currently selected file in the IDE and map it to the Run File command.
By default, the IDE does not specify a main class, runtime arguments, and JVM arguments, and
the runtime classpath of each standard project contains the project's compiled classes and
everything in the project's compilation classpath. You can view the project's compilation
classpath by clicking Compiling Sources in the right panel of the Project Properties dialog box.
To change these runtime options, right-click the project node in the Projects window choose
Project Properties, and click Running Project in the left pane of the dialog box. Now follow the
instructions below.
Click the buttons to the right of the Classpath for Running Project list to add projects, libraries,
JAR files, and folders to the project's runtime classpath.
If your project uses special libraries dynamically at runtime through an indirect interface or
reflection (like JDBC drivers or JAXP implementations), you have to add these libraries to the
runtime classpath. You also have to adjust your runtime classpath if the runtime dependencies
between your projects do not match the compilation dependencies between the projects. For
example, imagine that project A compiles against project B, and project B compiles against
project C, but project A does not compile against project C. This means that project A only has
project B on its runtime classpath. If project A requires both project B and project C during
execution, you have to add project C to project A's runtime classpath.
In free-form projects, your Ant script handles the classpath for all of your source folders. The
classpath settings for free-form projects only tell the IDE what classes to make available for code
completion and refactoring.
Type the fully qualified name of the main class in the Main Class field (for example,
org.myCompany.myLib.MyLibClass). The main class must exist in the project or in one of the
JAR files or libraries in the project's runtime classpath. Type any runtime arguments in the
Arguments field.
If you use the Browse button to choose the project main class, the file chooser only shows
classes in your project source directory. If you want to specify a class in one the libraries on the
classpath, you have to type the fully-qualified name of the class in the Main Class field.
You can set system properties by typing the following in the VM Options field:
-Dname=value
\
Debugging Applications
Debugging is the process of examining your application for errors. You debug by setting
breakpoints and watches in your code and running it in the debugger. You can execute your code
one line at a time and examine the state of your application in order to discover any problems.
The IDE uses the Sun Microsystems JPDA debugger to debug your programs. When you start a
debugging session, all of the relevant debugger windows appear automatically at the bottom of
your screen. You can debug an entire project, any executable class, and any JUnit tests. The IDE
also lets you debug applications that are running on a remote machine by attaching the
debugger to the application process.
When you run or debug web applications, JSP pages, or servlets, you can also use the HTTP
Monitor to monitor data flow. The HTTP Monitor appears by default. The HTTP Monitor gathers
data about HTTP requests that the servlet engine processes. For each HTTP request that the
engine processes, the monitor records data about the incoming request, the data states
maintained on the server, and the servlet context. You can view data, store data for future
sessions, and replay and edit previous requests. For details on the HTTP Monitor, choose Help >
Help Contents in the main menu.
For free-form projects, you have to write an Ant target for the Debug Project command. You can
also write targets to debug specific files and map these targets to the project's commands.
● Basic Debugging
❍ Starting a Debugging Session
❍ Debugger Windows
❍ Stepping Through Your Code
● Working With Breakpoints
❍ Setting a Breakpoint
❍ Setting Conditions for Breakpoint
❍ Customizing the Output for a Breakpoint
❍ Breakpoint Types
● Setting Watches
Basic Debugging
In this section, we will use a simple example to demonstrate how to start a debugging session,
step through your code manually, and monitor variables and method calls in the Debugging
workspace. We will leave more advanced functions like setting breakpoints and watches for the
following sections.
Our example for this section is the Array Fill application. This application is very simple. It
creates an array of sampleBeans, each one of which has two properties, firstName and
lastName. It then assigns values to the properties of each bean and prints out the values.
The first thing you want to do is run the application to see if it throws any exceptions. Create a
Java application (Ctrl-Shift-N). Type Array Fill in the Project Name text box and specify a
folder to house your project in the Project Location text box. Notice that the IDE uses the project
name to fill the Create Main Class text box with arrayfill.main. This means that the main class
main will be created in the package arrayfill. Change the name of the main class to
arrayFill, so that the Create Main Class text box contains arrayfill.arrayFill. Click Finish.
The new Java application is created and you can view it in the Projects window or Files window.
Right-click the arrayfill package, choose New > Java Class, name the class sampleBean, and
click Finish. Now insert the code that is attached to this page in your classes arrayFill.java
and sampleBean.java. Make sure that arrayfill is the package declared in your Java classes.
When you have inserted the code, right-click arrayFill.java and press Shift-F6 to execute it.
The following output should appear in the Output window:
java.lang.NullPointerException
at arrayFill.loadNames(arrayFill.java:27)
at arrayFill.main(arrayFill.java:34)
Exception in thread "main"
Java Result: 1
When you start a debugging session in the IDE, the IDE compiles the files that you are
debugging, runs them in debug mode, and displays debugger output in the Debugger windows.
To start a debugging session, select the file that you want to debug and choose one of the
following commands from the Run menu:
● Debug Main Project (F5). Runs the main project until the first breakpoint is
encountered.
● Step Into (F7). Starts running the main project's main class and stops at the first
executable statement.
● Run to Cursor (F4). Starts a debugging session, runs the application to the cursor
location in the Source Editor, and pauses the application.
If more than one project is open in the IDE, make sure that Array Fill is the main project.
Then press F7 to step into the main project's main class. If you did not set a main class, the IDE
prompts you to set it. Then the IDE opens the file in the Source Editor, displays the Output
window and Debugger windows, and stops just inside the main method.
Debugger Windows
Let's take a minute to look at the Debugger
windows. The Debugger windows
automatically open whenever you start a
debugging session and close when you finish
the session. By default, the IDE opens three
Debugger windows: the Local Variables
window, Watches window, and Call Stack
window.
Local Variables Alt-Shift-1 Lists the local variables that are within the current call.
Watches Alt-Shift-2 Lists all variables and expressions that you elected to watch while
debugging your application.
Call Stack Alt-Shift-3 Lists the sequence of calls made during execution of the current
thread.
Classes Alt-Shift-4 Displays the hierarchy of all classes that have been loaded by the
process being debugged.
Sessions Alt-Shift-6 Lists the debugging sessions currently running in the IDE.
Sources Alt-Shift-8 Lists the source directories on your project classpath. You can set
whether to step into or step over classes by deselecting their
source folders here. The IDE automatically steps over JDK
classes; if you want to step into them, select the JDK sources in
this window.
You can use the following commands in the Run menu to control how your code is executed in
the debugger:
● Step Over (F8). Executes one source line. If the source line contains a call, executes the
entire routine without stepping through the individual instructions.
● Step Into (F7). Executes one source line. If the source line contains a call, stops just
before executing the first statement of the routine.
● Step Out (Alt-Shift-F7). Executes one source line. If the source line is part of a routine,
executes the remaining lines of the routine and returns control to the caller of the routine.
● Pause. Pauses application execution.
● Continue (Ctrl-F5). Continues application execution. The application will stop at the next
breakpoint.
● Run to Cursor (F4). Runs the current session to the cursor location in the Source Editor
and pauses the application.
initiates the array that holds the beans, it does not initiate the beans themselves. The individual
beans have to be initiated in the loadNames method by adding the following code in line 28:
names[i]=new sampleBean();
Most applications are far too big to examine one line at a time. More likely, you set a breakpoint
at the location where you think a problem is occurring and then run the application to that
location. You can also set more specialized breakpoints, such as conditional breakpoints that only
stop execution if the specified condition is true or breakpoints for certain threads or methods.
In this section, we will use the arrayFill application from the last example, so you will have to
recreate the bug by commenting out the code you added above.
Setting a Breakpoint
If you just want to set a simple line breakpoint,
you can click the left margin of the desired line.
A line breakpoint icon ( ) appears in the
margin. You can remove the line breakpoint by
clicking it again.
Conditional breakpoints only stop execution if a specified boolean expression is true. If you want
to set a conditional breakpoint, open the New Breakpoint dialog box and enter an expression in
the Condition field.
For example, open arrayFill.java, set the insertion point in the loadNames method call in the
main method, and press Ctrl-Shift-F8. In the dialog box, enter myNames=null in the Condition
field and click OK. The conditional breakpoint icon ( ) appears in the margin before the method
call. Then press Alt-F5 to start debugging the application. The execution should break at the
loadNames method call.
Customizing the Output for a Breakpoint
In the New Breakpoint dialog box, you can also specify what information is printed when a
breakpoint is reached. Enter any message in the Print Text field at the bottom of the dialog box.
You can use variables to refer to certain types of information you want displayed.
Breakpoint Types
The following table lists the different breakpoint types that are available.
Type Description
Line You can break execution when the line is reached, or when elements in
the line match certain conditions.
Exception You have several options for setting a breakpoint on an exception. You
can break whenever a specific exception is caught, whenever a specific
exception is not handled in the source code, or whenever any exception is
encountered regardless of whether the application handles the error or
not.
Thread You can break application execution whenever a thread starts, stops, or
both.
Class When you set a breakpoint on a class, you can stop the debugger when
the class is loaded into the virtual machine, unloaded from the virtual
machine, or both.
Setting Watches
A watch enables you to track the changes in the value of a variable or expression during
application execution. To set a watch, select the variable or expression you want to set a watch
on in the Source Editor, then right-click and choose New Watch (Ctrl-Shit-F7).
You can also create fixed watches in the Watches view. While a normal watch describes the
content of a variable, a fixed watch describes the object that is currently assigned to the
variable. To create a fixed watch, right-click any item in the Local Variables or Watches view and
choose Create Fixed Watch.
Developing Web Applications
A web application is a term used in the JavaServer Pages Specification and Java Servlet
Specification. It roughly corresponds to the J2EE term "web module". A web module is the
smallest deployable unit of web resources in a J2EE application. It corresponds to a "servlet
context" as defined in the J2EE specification.
To compile a project, package, or file, select it in the Projects window and choose one of the
following from the main window:
● In the main menu, choose Build > Build Main Project (F11) to build the main project.
● In the main menu, choose Build > Clean and Build Main Project (Shift+F11) to clean
and build the main project.
● Right-click the project in the Projects window and choose Build Project to build a project.
● Right-click the project in the Projects window and choose Clean Project to clean a project.
● Right-click the package in the Projects window and choose Compile Package (F9) to
compile a package.
● Right-click the file in the Projects window and choose Compile File (F9) to compile a file.
Alternatively, choose Build > Compile File (F9). If you are using a free-form project, this
command is disabled by default. You have to write an Ant target for compiling the currently
selected file in the IDE and map it to the Compile File command.
For redefining a WAR file, the following table lists some common tasks:
Specify which Right-click the project node in the Projects window and choose Properties.
files are added to Click Packaging Project and configure the filter and compression settings.
a WAR file. See the Regular Expressions table below for details.
Change a WAR In the Files window, go to the nbproject folder in your project folder and
file's name and open project.properties in the Source Editor. Enter the full path to the
location. WAR file in the dist.dir property and the WAR file's name in the war.name
property. Notice that these two properties are concatenated to form the
dist.war property.
Disable the In the Files window, open your project folder and open build.xml.
generation of a Override the do-dist target to have no contents and no dependencies. For
WAR file for a example, add the following to build.xml:
project.
Any compilation errors and output are displayed in the Output window.
For general information on customizing the build process, see Customizing the Build Process.
To compile a project, package, or file, select it in the Projects window and choose one of the
following from the main window:
● In the main menu, choose Run > Run Main Project (F6) to run the main project.
● Right-click the project in the Projects window and choose Run Project to run a project.
● Right-click the file in the Projects window and choose Run File (Shift+F6) to run a file.
Alternatively, choose Run > Run Other > Run File (Shift+F6). If you are using a free-
form project, this command is disabled by default. You have to write an Ant target for
running the currently selected file in the IDE and map it to the Run File command.
Any compilation errors and output are displayed in the Output window.
When you execute a web application on the server, the server uses a context path setting to
derive the path to the web application. For example, if the context path is /MyWebApp, then you
can access a file named index.html under the web application's document base (root directory)
by using the URL http://host:port/MyWebApp/index.html.
You should set a context path for a web application if you plan to execute different web
applications on the same server. Otherwise, files with the same name will overwrite files from
other web applications. When you create a web application from the New Project wizard, the
default context path is derived from the name of the document base (root directory).
To set the context path, right-click the project node in the Projects window and choose Properties
from the contextual menu. In the Project Properties dialog box, select the Running Project page,
and type the Context Path. The path must begin with a forward slash (/), such as /MyWebApp.
When you change the context path in the Project Properties dialog box, the IDE updates the
context descriptor (web/META-INF/context.xml) to match.
Setting the Web Server
During development and testing, you can execute your web application using any server installed
in the IDE that implements a J2EE-compliant web container. By default, the IDE executes web
applications using the Server Registry's default web server. To change the default web server,
right-click the project node in the Projects window and choose Properties. Click Running Project in
the Project Properties dialog box and then choose the appropriate web server from the Server
drop-down.
The IDE uses the IDE's default web browser to run a web application. You can set the default web
browser to be one of the supported browsers, such as the supported versions of Mozilla,
Netscape, and Internet Explorer, or to be the IDE's internal web browser. You can also configure
the IDE to use other browser types.
Choose Tools > Setup Wizard from the main menu. Select a browser from the Web Browsersdrop-
down. You cann choose from the following web browsers:
● Default System Browser.
The browser that is registered as your operating system's default browser.
● Swing HTML Browser.
A simple HTML browser based on a Swing component. The internal Swing HTML browser
provides a higher level of integration with the IDE than an external browser. You can
embed the Swing HTML browser into another IDE window or an MDI frame.
● Any other browser installed on your computer.
Setting Parameters
You can pass request parameters in URL query string format to JSP pages and servlets from the
IDE. Specifying input data in this fashion provides a useful aid in testing for expected JSP or
servlet output.
To specify parameters for a JSP page, right-click the JSP file in the Projects window and choose
Properties. In the Request Parameters dialog box, type the parameters in the URL query string
format. A URL query string is a string appended to the URL for passing parameter values in a GET
request. The query string must begin with a question mark (?). The parameters must be in
name/value pairs, with the pairs separated by ampersands (&). The names and values must be
URL-encoded. For example, white space is encoded as +. The following URL shows an example of
a query string:
http://www.myapp.com/sayhello?name=Fido+Filbert&type=Dog
To specify parameters for a servlet, select the servlet in the Projects window, and choose Tools >
Set Servlet Execution URI in the main menu. Alternatively, right click the servlet and choose
Tools > Set Servlet Execution URI from the contextual menu. Type the execution URI and
parameters.
The IDE saves the parameters and automatically passes them to the JSP or servlet the next time
you run it. Note that the HTTP Monitor tool enables you to edit and resend request parameters.
Connecting to Databases
This section explains the basics of using the IDE to create a connection from a web application to a database. The
web application is deployed using a Tomcat web server and data from a MySQL database are displayed on a JSP
page.
You use JavaTM Database Connectivity (JDBCTM) technology to connect to a database. The JDBC application
programming interface (API) is Sun Microsystems' API for connecting to databases that support Structured Query
Language (SQL). The JDBC API is a package of object-oriented objects that includes Connection, ResultSet, and
Statement. Each object contains various API methods, for example, connect(), close(), and prepareStatement().
You will use these objects and methods later in this section. To do so, you need to use a database that supports SQL.
A database runs in a database server. If you don't have a database server, you can download one from the Internet.
This section focuses on the open-source database server MySQL, but the instructions that follow should be equally
applicable to most other SQL databases. You can download the MySQL database server for free from its vendor's site.
Once you've downloaded and installed your SQL database server, follow the vendor's instructions to start it.
A driver supporting the JDBC API ("JDBC driver") translates JDBC calls into the network protocols that are used by
SQL databases. Since many of these network protocols are proprietary, the MySQL vendor itself is the primary source
for the driver that works with its database server. If the MySQL JDBC driver is made available to your IDE, you can
make direct calls from the IDE to the database. If the MySQL JDBC driver is made available to your web application,
you can make direct calls from your web application to the database using your web server.
A MySQL driver can be downloaded for free from its vendor's site. Note that you are recommended to get a type 4
driver, because it is a pure Java driver. You can search for the database driver of your choice by using Sun's JDBC
Data Access API site.
Once you've downloaded and installed your database driver, make it available to your IDE and your web applications,
when appropriate, according to the instructions that follow.
● Connect to a database
● Choose a driver for your database
● Fill in the appropriate driver for your database
● Create, browse and edit database structures
● Enter SQL queries and see the results immediately
● Connect to multiple databases concurrently
● Migrate table schemas across databases from different vendors
In this section, you will use a simple example to demonstrate how to make a database driver available to the IDE,
use the database explorer to create a a database, connect to the database, create a table, populate it with values,
and view the values. We will explain how to use the data in a web application in subsequent sections. Note that using
the database explorer is not a prerequisite for making a database connection from a web application. Our example for
this section is the db_emp database. It contains a record for an employee's first name, last name, and age. The
records are in a table called t_emp, which consists of the fields emp_id, f_name, l_name, and age.
To get started, view the Runtime window. If the Runtime window is not displayed by default, choose Window >
Runtime (Ctrl-5) from the main menu. Expand the Databases node. The Database Explorer is displayed.
Before you can use the Database Explorer to work with your database, you must make your database's driver
available to the IDE. To do so, right-click the Drivers node and choose Add Driver from the contextual menu. The Add
JDBC Driver dialog box appears. Click Add and browse to where you downloaded your database driver and select the
database driver's JAR or ZIP file. The Database Explorer fills the other fields in the dialog box.
If the Driver Class field is empty or incorrect, click Find. The IDE searches the JAR file that you selected and finds all
classes that implement the JDBC API Driver interface (java.sql.Driver). The Driver Class combo box lists the
classes that the IDE finds. Use the combo box to select the driver class that you need and click OK.
Now, when you expand the Drivers node in the Database Explorer, a new node is displayed for the new driver you
added. The nodes under the Drivers node are all the potential drivers you can use. This is what the icons mean:
Icon Description
The driver can be loaded by the IDE and you can connect to the database.
The IDE cannot connect to the database using this driver because the driver's JAR or ZIP file isn't placed in
the specified location. You can correct the location by right-clicking the driver node and choosing Customize.
Note that when you have made your database driver available to the IDE, you have not made it available to your web
application. At this stage, you can use the IDE to access and modify your database. You cannot access and modify
your database from your web application yet. To be able to do so, your database driver's JAR file needs to be in your
web application's WEB-INF/lib folder or, for Tomcat connection pooling, in Tomcat's common/lib folder. For details,
see the instructions that apply in the sections that follow.
The database server that you downloaded provides functionality and instructions for creating a database. In the case
of MySQL, you can use the IDE to create a database. To do so, right-click your driver's node and choose Connect
Using from the contextual menu. Now type the following URL in the Database URL text box:
jdbc:mysql:///
Next, specify the username and password that you defined when you installed your database server. If you do not
specify these, you will not be able to execute the SQL commands required to create the database. Click OK.
Right-click the node for your database connection. Choose Execute Command from the contextual menu. The
jdbc:mysql:/// tab is displayed. Type the following SQL command in the Command text box:
Click Execute. Below the Command history drop down, you should now see the message "Command successfully
executed."
Create the Table
To connect to your database, right-click your driver's node and choose Connect Using from the contextual menu. Each
database server has different requirements for the syntax of a database URL. For MySQL, type the following URL in
the Database URL text box:
jdbc:mysql://localhost:3306/db_emp
Specify the username and password that you defined for your database server and click OK. When you expand the
Databases node, you should now see a node with a URL that includes the name of your database.
Now expand the node for your db_emp database, right-click the Tables node, and select Create Table. Type t_emp in
the Table name text field and define the table as shown in the illustration below. After filling out the first row, click
Add Column to display a new row for input.
Alternatively, right-click the node for your db_emp database, select Execute Command from the contextual menu and
execute the following command:
To populate the table, right-click the node for your db_emp database and choose Execute Command from the
contextual menu. Now execute the following command:
Execute the above command again a few times, but keep changing the values.
Right-click the t_emp table in the Database Explorer and choose View Data from the contextual menu. The following
command is executed to retrieve all the data in your t_emp table:
The values that you inserted into the table are displayed.
Note that when you expand the t_emp node, you can right-click each field and choose View Data, to view the values
of each field in the table.
MVC is a programming paradigm in which the application is separated into the following distinct parts:
● The model maintains the data that describes the state of the application.
● The view provides one or more views of the data.
● The control provides a conduit for data to enter the view.
It is good programming practice to access data using the control (a servlet or a JavaBeans component) only.
However, for small applications or for testing during the development phase, you may want to quickly query your
database by using SQL commands from a JSP page, which is the Java implementation of the view. This section
outlines two strategies for doing this. The first shows you the simplest way of connecting to a database. Here, you
use a JSP page to make a direct connection to your database and query your data. However, if you create a new
connection to the database for each of your requests, you are wasting your web application's resources. For this
reason, the second strategy shows you how you can pool your connections to enhance data access efficiency.
The first thing you want to do is add the database driver's JAR file and the JSTL 1.1 library to your web project's
compilation classpath. Note that you need to let the Tomcat web server know that the JSP page uses tags from JSTL's
CORE component and JSTL's SQL component. To do so, add the following taglib directives after the page directives,
which are at the top of your JSP file:
Next, create a data source by adding the following code below the JSP file's taglib directives:
<sql:setDataSource var="datasource"
url="jdbc:mysql://localhost:3306/db_emp" driver="org.gjt.mm.mysql.Driver"
user="root" password=""/>
Finally, to make the web application display the retrieved data in a table, add the following to the JSP page:
<table border=1>
<tr>
<th>First</th><th>Last</th>
</tr>
<c:forEach var="row" items="${queryresults.rows}">
<tr>
<td><c:out value="${row.f_name}" /></td>
<td><c:out value="${row.l_name}" /></td>
</tr>
</c:forEach>
</table>
When you run the web project, the web application is deployed in the IDE's default browser and displays the data in a
page similar to the illustration below.
Connect Using a Tomcat Database Connection Pool
A database connection pool is a group of reusable connections that a server maintains for a particular database. Web
applications requesting a connection to a database obtain that connection from the pool. When an application closes a
connection, the connection is returned to the pool. Connection pool properties may vary with different database
vendors. Some common properties are the URL for the database name, user name, and password.
The first step in creating a Tomcat database connection pool is to create a JDBC resource (also called a data source).
A JDBC resource provides applications with a connection to a database. Typically, there is at least one JDBC resource
for each database accessed by an application. It is possible to have more than one JDBC resource for a database. You
can create a JDBC resource manually in your server.xml or you can use Tomcat's Admin tool to do so. Be aware that
you hand-edit the server.xml file at your own risk; the IDE cannot repair a damaged server.xml file. Therefore, you
are strongly encouraged to use the Tomcat Admin tool instead of editing server.xml by hand.
The Tomcat Admin tool is bundled with the IDE. You can access it from the IDE in the Runtime window by expanding
the Server Registry node and the Tomcat 5 Servers node. If the text to the right of the Tomcat instance node does
not end with "[running]", start the server by right-clicking the Tomcat instance node, choosing Start/Stop Server, and
clicking Start Server. When the server is running, expand the Web Applications node. Right-click the node for the
/admin context and choose Open in Browser. The Tomcat Server Administration Tool opens in the IDE's default web
browser.
Type a User Name and Password for a Tomcat user to whom the "admin" role has been assigned. If the Admin tool
does not open when you click Login, or if you don't have a user name or password, check the tomcat-users.xml file
in Tomcat's base directory. To identify the location of this directory, right-click the Tomcat server instance node in the
Runtime window and select Properties. In the Properties dialog box, the Base Directory property points to Tomcat's
base directory. In the tomcat-users.xml file in Tomcat's base directory, check that a role called "admin" exists and
that the role is assigned to a user. If necessary, define the "admin" role, assign the "admin" role to a user, save the
file, and, using the Runtime window, stop and restart the Tomcat instance.
In the Admin tool, click Data Sources. Choose Create New Data Source from the Data Source Actions combo box on
the right. Type values such as the following to define your data source:
Next, you need to reference the data source in your web project. To do so, expand the web project's META-INF node.
Right-click the context.xml node, choose Edit from the contextual menu and use the Source Editor to add the
following resource link between the <context> tags in the context.xml file:
Do not double-click the context.xml file. If you do so, the IDE opens the context.xml file in the Context Editor
instead of the Source Editor. You cannot add a resource link in the Context Editor. As you cannot open the
context.xml file in both the Source Editor and the Context Editor at the same time, the IDE disables Edit in the
contextual menu if the context.xml file is opened in the Context Editor.
Your web application's META-INF/context.xml file should now look similar to the following:
<Context path="/MyWebApp">
<ResourceLink name="jdbc/poolDB" type="javax.sql.DataSource" global="jdbc/poolDB"/>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="MyWebApp" suffix=".log"
timestamp="true"/>
</Context>
Once you've set up your connection pool, make the database driver's JAR file available to Tomcat connection pooling
by copying the database driver's JAR file into Tomcat's common/lib folder, within the NetBeans installation folder. If
you have already started the Tomcat web server, make sure that you restart it after you copy the database driver's
JAR file, so that the Tomcat web server can load the JAR file.
Next, add the bundled JSTL 1.1 library to your web project's compilation classpath. Note that you need to let the
Tomcat web server know that the JSP page uses tags from JSTL's CORE component and JSTL's SQL component. To do
so, add the following taglib directives after the page directives, which are at the top of your JSP file:
Now modify the JSP file to enable the selection of database records via the connection pool. In the code below, make
sure to specify the same JNDI name for the data source as specified in the Tomcat Admin tool above:
Finally, to make the web application display the retrieved data in a table, add the following to the JSP page:
<table border=1>
<tr>
<th>First</th><th>Last</th>
</tr>
<c:forEach var="row" items="${queryresults.rows}">
<tr>
<td><c:out value="${row.f_name}" /></td>
<td><c:out value="${row.l_name}" /></td>
</tr>
</c:forEach>
</table>
When you run the web project, the web application is deployed in the IDE's default browser and the JSP page is
displayed in the same way as in the previous example.
Troubleshooting
● Error message:
javax.servlet.ServletException: Unable to get connection, DataSource invalid:
"org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect
URL 'null'"
❍ Did you correctly add your data source to the server.xml file? For example, if you did not click Commit
Changes in the Tomcat Admin tool, the data source is saved in Tomcat's Admin tool, but not in the
server.xml file. Open the server.xml file and check that it includes the data source you defined in
Tomcat's Admin tool.
❍ Did you correctly add a resource link in the context.xml file? Without a resource link, your web
application cannot find your data source, which is in your server.xml file. Check your context.xml file.
❍ Does your resource link reference the data source correctly? Check that the resource link has the same
name as the data source. To do so, open your context.xml file and your server.xml file and make sure
that the name of the resource link is the same as the name of your data source.
● Error message:
javax.servlet.ServletException: Unable to get connection, DataSource invalid:
"org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class
'org.gjt.mm.mysql.Driver'"
❍ Is your database driver's JAR file in Tomcat's common/lib folder? If your database driver is not in
Tomcat's common/lib folder, your Tomcat connection pool is unable find it and your web application is
unable to connect to the database.
❍ Did you stop and restart the Tomcat Server after you copied the database driver's JAR file in in Tomcat's
common/lib directory? If you did not restart the Tomcat Server, the Tomcat Server is unable to load
your database driver's JAR file.
Using Ant Scripts in the IDE
Apache Ant is a Java-based build tool used to standardize and automate build and run environments for
development. Ant build scripts are XML files that contain targets, which in turn contain tasks. Ant tasks
are executable bits of code that handle the processing instructions for your source code. For example,
you use the javac task to compile code, the java task to execute a class, and so forth. You can use
Ant's built-in tasks, use tasks written by third parties, or write your own Ant tasks.
The IDE's project system is built directly on top of Ant. All of the project commands, like Build Project or
Run File in Debugger, call targets in the project's Ant script. You can therefore build and run your
project outside the IDE exactly as it is built and run inside the IDE.
You do not need to know Ant to work with the IDE. You can set all the basic compilation and runtime
options in the project's Project Properties dialog box and the IDE automatically updates your project's
Ant script. If you know how to work with Ant, you can customize a standard project's Ant script or write
your own Ant script for your project.
When you create a target that you want to run from the
command line, give the target a description attribute. Then,
if you forget the names of the targets or what they do, you can run the ant -projecthelp <script>
command from the command line. With this command, Ant lists only those targets that have a
description attribute, together with their descriptions. Especially when there are many targets in your
Ant build script, emphasizing some and de-emphasizing others can be a useful way to distinguish
between those that you use a lot and those that you use less often.
The font style of a subnode's label in the Projects, Files, and Favorites windows indicates the following:
● Normal
A target that is defined within the current Ant script.
● Italics
A target that is imported from another Ant script.
● Greyed out
An internal target that cannot be run directly. Internal targets have names beginning with '-'.
● Bold
The default target for the script, if there is one. The default target is declared as an attribute of
the project, together with other project attributes, such as its name. You define the project's
default attribute in the Source Editor.
Targets that are imported from another script but are overridden in the importing script are not listed.
Only the overriding target is listed.
In standard projects, Ant scripts are stored in your project folder. The main Ant script for a standard
project is build.xml. The IDE calls targets in build.xml whenever you run IDE commands. This file
contains a single import statement that imports targets from build-impl.xml. In build.xml, you can
override any of the targets from build-impl.xml or write new targets. In standard projects, build-
impl.xml is the Ant script that contains all of the instructions for building, running, and debugging the
project. You should never edit this file. You can, however, open it to examine the Ant targets that are
available to be overridden.
In free-form projects, there is no build-impl.xml. The IDE directly calls targets in the free-form
project's Ant script.
Even if you are an expert at using Ant, you probably still need to look in the Ant manual every once in a
while. You can install the Ant manual directly in the IDE help system by going to the NetBeans Update
Center and installing the Ant Documentation module. See Installing New Modules from the Update
Center for more information on using the Update Center.
The easiest way to edit an Ant script is in the Source Editor. All of the normal XML search tools,
selection tools, and keyboard shortcuts are available for editing Ant scripts. Double-click any of the Ant
script's subnodes to jump to that target's location in the Source Editor. The IDE provides code
completion for all standard Ant tasks. To enter an end tag for any empty beginning tag, type </.
● Add instructions to be processed before or after an Ant target is run. Each of the main targets in
build-impl.xml also has a -pre and -post target that you can override in build.xml. For
example, to get RMI working with regular projects, type the following in build.xml:
<target name="-post-compile">
<rmic base="${build.classes.dir}" includes="**/Remote*.class"/>
</target>
● Change the instructions in an Ant target. Copy the target from build-impl.xml to build.xml
and make any changes to the target.
● Create new targets in build.xml. You can also add the new target to the dependencies of any of
the IDE's existing targets. Override the existing target in build.xml then add the new target to
the existing target's depends property. For example, the following adds the new-target target to
the run target's dependencies:
<target name="new-target">
<!-- target body... -->
</new-target>
Notice that you do not need to copy the body of the run target into build.xml.
Note that there is no build-impl.xml in free-form projects. In these projects, the IDE directly calls
targets in the project's Ant script.
If you are working in a team, it is important that all of your build scripts be portable and usable on each
developer's computer. Local details like the location of various libraries and executables can vary from
computer to computer. One way to deal with this is to define these locations as properties.
Note that you create your own property files in free-form projects.
You can specify runtime parameters for each target. Choose Advanced from the Ant script node's Run
Target submenu, select a target to run, and specify its properties. Specify properties as name-value
pairs to pass to Ant, one pair per line. For example:
build.compiler.emacs=true
Initially, only the global properties that are defined under the Ant Settings in the Options dialog are
shown. You can also change the verbosity level, which is defined globally under the Ant Settings in the
Options dialog. The changes you make to the parameters and verbosity level are saved in your user
directory. If you open the advanced dialog again in subsequent IDE sessions, the previously used
changes are used to initialize the fields. This makes it easy to test targets with particular properties
several times in a row without needing to type the same values each time.
Instead of running a target by using the Ant script node's contextual menu, you can simply right-click
the target's node and choose Run Target.
In standard projects, you may want to extend your application's functionality by writing new Ant targets
or by customizing the Ant targets provided by the IDE. In a free-form project, however, you have to
write all Ant targets yourself. For example, you have to write an Ant target to run a project in the
debugger. An example of a debug target for a J2SE application is as follows:
For examples of other targets, see debug a web application and compile/run/debug a single file.
In free-form projects, you map IDE commands to targets in your Ant script. By doing so, you can, for
example, add an item for a Debug Project target to the project's contextual menu.
Click Build and Run in the left panel of the Project Properties dialog box.
For each command, choose an Ant target from the drop-down. The drop-down contains each of the
targets in your Ant script. However, if your Ant script uses an <import> statement to import targets
from another Ant script, the targets do not show up in the drop-down list in the Project Properties dialog
box. To map commands to these targets, type the names of the targets into the list.
You can also add a shortcut to an Ant target by right-clicking a target's node in the Projects window,
Files window, or Favorites window, and choosing Create Shortcut from the contextual menu. Use the
wizard to create a shortcut to the target. For example, if you have several runnable classes that you
need to run often, you can write targets to run these classes and then run them using a shortcut.
You map other commands, like those that run on individual files, by editing the project.xml file
manually. For details, see Advanced Free-form Project Configuration.
You can use custom Ant tasks to expand on the functionality provided by Ant's built-in tasks. Custom
tasks are often used to define properties, create nested elements, or write text directly between tags
using the addText method.
To create a custom Ant task in the IDE, press Ctrl-N and select the Custom Task template from the Ant
Build Scripts folder. The Custom Task contains sample code for many of the common operations
performed by Ant tasks. Make sure that you add ide4/ant/lib/ant.jar file to your project's compilation
classpath, as instructed in the sample code. After each section of code, the template also shows you
how to use the task in an Ant script.
For example, let's make our custom task create a simple option and a simple property and echo their
values. Remove the comments from the following lines of code in MyTask:
Now let's add a target to our build.xml script that give values to the option and property in
MyTask.java. Add the following to build.xml:
<target name="mytask">
<javac classpath="${ant.location}" destdir="build/taskclasses" srcdir="tasksource"/>
<taskdef classname="examples.MyTask" classpath="." name="mytask"/>
<mytask myprop="hello" opt="true"/>
</target>
You should define the ant.location property with the path to your Ant JAR, either in the build script
itself or in a properties file. You can also enter the path to the Ant JAR directly in the javac task. Then
expand the build.xml node in the Projects window, Files window, or Favorites window, right-click the
mytask target, and choose Run Target from the contextual menu. The target is run and the Output
window displays the values of myprop and opt.
By default, the IDE ignores your environment's CLASSPATH variable whenever it runs Ant. For your Ant
script to use customs tasks, you must add the tasks to the Ant's classpath in the IDE.
You can add custom tasks to Ant's classpath within the IDE by:
● Providing an explicit classpath to the tasks in your build script. This is the recommended method.
● Configuring the Additional Classpath property under Ant Settings in the Options window.
Using an explicit classpath is the recommended method, as it ensures that your build scripts will be fully
portable. You can write your tasks and include instructions to compile them and produce a JAR file in
the build file. To use these tasks, include the long form of taskdef, which includes a classpath. Here is
a simple example of such a task:
The advantage of this method is that no special preparation is needed to begin using the script. The
script is entirely self-contained and portable. This method also makes it easier to develop your tasks
within the IDE, as the script compiles them for you automatically.
To make the your build scripts even more robust, use a property instead of a hard-coded location to
specify the classpath to your tasks. You can store the property in the build script itself or in a separate
ant.properties file. You can then change the classpath setting throughout your script by simply
changing the value of the specified property.
If you cannot declare a classpath in your build script, or you are using third-party build scripts which
you cannot alter, you can add the tasks to Ant's classpath in the IDE. Open the Options window, select
Building > Ant Settings, and type the full path to the binary in the Additional Classpath property.
Configuring the IDE
One of the main strengths of NetBeans IDE is its versatile configurability. You can customize your
working environment to fit your needs and personal development style. Having all of these
options can, however, make it difficult to find the exact setting you are looking for.
When you configure project-level settings, such as a project's properties and JDK level, see
Setting Up Projects in the IDE.
The main tool for configuring default settings in the IDE is the Options window. You can open the
Options window by choosing Tools > Options.
IDE settings are grouped under Options window nodes in the left panel of the window. Select any
node to set its properties in the right panel of the window. As with regular property sheets, many
properties in the Options window contain special property editors. You can tell that a property
editor is available for a property if the property contains an ellipsis button, as in the Ignored Files
property in the figure above.
You can revert a node's settings to the IDE's defaults by clicking the << at the top of the options
window, clicking the node's cell in the Default column, and choosing Revert Def.
Another tool for configuring the IDE is Java startup switches. You can add startup switches to
NetBeans IDE on the command line or by entering them in a special file called netbeans.conf,
which is located in the etc folder. You can enter IDE-specific startup switches and pass
arguments directly to the JVM in which the IDE runs.
For example, to set the -Xmx (maximum heap size) for the JVM in which NetBeans IDE runs,
either add the line -J-Xmx64m to your netbeans.conf file or launch the IDE by typing
./netbeans.sh -J-Xmx64m
The netbeans.conf file can have the various JVM switches separated either by spaces or on
separate lines. Note that the Sun JVM does not start when switches are passed that it does not
understand. When this error occurs, the JVM returns a message pointing out the switch that
caused the problem, as with the following example:
java -foo
Unrecognized option: -foo
Could not create the Java virtual machine.
The following table lists the startup switches that are available.
Startup Switch Description
--fontsize size Set the font size, expressed in points, in the IDE's user
interface. If this option is not used, the font size is 11 points.
--jdkhome jdk_home_dir Use the specified version of the JavaTM 2 SDK instead of the
default SDK. By default on MicrosoftTM Windows systems, the
loader looks into the registry and uses the latest SDK available.
You should back up your user directory before you upgrade the
SDK that the IDE uses. If you later need to revert to the
previous JDK, switch to the backed up user directory to ensure
that you do not lose any settings.
-J-Dsun.java2d.noddraw=true Prevent the use of DirectX for rendering. This switch might
prevent problems that occur on some Microsoft Windows
systems with faulty graphics cards.
-J-Dnetbeans.debugger.jpda.transport=dt_shmem userdir Force the IDE to use the shared memory connection when
starting a debugging session with the Debug > Start command.
This parameter has no effect when you attach the debugger to
an already running process.
--laf UI_class_name Selects the given class as the IDE's look and feel. The following
are two examples of look and feel classes:
● com.sun.java.swing.plaf.motif.MotifLookAndFeel
● javax.swing.plaf.metal.MetalLookAndFeel
--userdir userdir Explicitly specify the userdir, which is the location in which user
settings are stored.
The first thing you should do to configure the IDE is make sure it is using the correct Java
Standard Development Kit (JDK) version. The JDK in which the IDE runs is important because it
is automatically used as the platform against which all of your sources are compiled and
executed. See Setting the Target JDK in a Project for details.
● Strings Table. Specifies the _USER_ macro in templates and enables you to create your
own macros for use in templates.
● Error Annotation Limit. Sets the amount of errors that are highlighted in the Source
Editor for each open file. Set this property to zero to disable error annotation for Java files.
● Show Compile Status. If True, displays the compile status badge on the node for a
Javaclass file when that file needs to be compiled.
● Automatic Parsing Delay. Specifies the time (in milliseconds) between a pause in typing
or moving around in the Source Editor and the time that internal parsing information is
refreshed. The default is two seconds. The IDE uses the internal parser to automatically
update information about the current Java source file. You can disable automatic parsing
by setting this property to zero. If this property is disabled, a Java file is parsed only when
the file is saved or compiled.
● Default Encoding. Specifies the default encoding that the IDE uses to display and save
.java files. Type an encoding name or leave blank to use your system's default encoding.
This setting does not affect the encoding used to compile classes in the IDE.
The IDE recognizes the standard file extensions for most types of files. For example, it knows
that files with the extensions .htm, .html, and .shtml should all be treated as HTML files. Many
file types, like XML, can have nonstandard file extensions that the IDE does not recognize.
When the IDE runs across a file whose extension it does not understand, it displays the file as a
generic file icon in the Filesystem window. You can right-click the file and choose Treat as Text to
open it in the Source Editor as a text file.
If you want to treat all files with a certain file extension as a certain type of file, go to the
Options window and expand IDE Configuration > System > Object Types. The Object Types node
contains all of the file types that the IDE is currently configured to work with. You can use the
Extensions and MIME Types property to specify which file extensions should be treated as a given
type of file.
For example, JavaHelpTM map files are XML documents that have a .jhm extension. You can treat
all JavaHelp map files as XML documents by adding .jhm to the list of Extensions and MIME
Types for the XML Object object type.
NetBeans IDE is a fully modular IDE, meaning that its functionality is provided by modules that
plug into the core NetBeans infrastructure. If you do not use the functionality provided by certain
modules, you can turn those modules off. Turning off unused modules helps improve your IDE's
startup time and performance. You can also add functionality to your IDE by downloading new
modules from the Update Center.
Disabling Modules
The Setup wizard is the most convenient tool for enabling and disabling modules. Disabling a
module only causes the IDE to ignore the module. The module is not deleted and it can be
enabled again at any time.
To open the Setup wizard, choose Tools > Setup Wizard, then click Next to go to the Module
Installation page of the wizard.
The Module Installation page groups related modules into module groups. For example, the Java
group contains all of the modules that deal with Java development. You can disable all modules
in a module group by unchecking the checkbox in its Enabled column, or expand the module
group node to disable individual modules. When only certain modules in a module group are
disabled, the Enabled column for the group displays [boolean]. When you are finished, click
Finish to activate your changes.
Certain modules depend on other modules to function properly. Disabling or enabling one of
these modules may require you to also disable or enable the modules upon which it depends. If
this is the case, the IDE displays a dialog that tells you which modules will also be disabled or
enabled and asks for your confirmation.
You can add functionality to your IDE by downloading new modules from the NetBeans Update
Center. To connect to the Update Center, choose Tools > Update Center from the main window.
In the Update Center wizard, select the Update Centers that you want to connect to. Make sure
that your proxy information is properly configured and that you can connect to the Internet. You
can edit your proxy configuration using the Proxy Configuration button on the wizard page. Click
Next when you are ready to proceed.
The second page of the wizard shows you all of the modules that are available on the Update
Centers. The wizard only displays modules that are not already installed in your IDE or newer
versions of modules that are already installed. Newer versions of modules that you already have
are marked with an upward arrow. Select any module to see detailed information about the
module, including a description, the version number of the module on the Update Center, and
the version number of the module already installed on your system.
To schedule a module for installation, select it in the window on the left and click the right arrow
button. To install an entire group of modules, select the module group node and click the double
right arrow. When you are ready to proceed, click the Next button to view the modules'
certificates and install the modules.
You can monitor your IDE's performance with the Memory toolbar. To view the Memory toolbar,
right-click anywhere in the toolbar area and select the Memory checkbox. The toolbar has a slide
that shows you how much of the IDE's memory is currently being used and how close it is to
automatically performing garbage collection. You can manually initiate garbage collection by
clicking the Memory toolbar button.
You can boost NetBeans performance by adjusting the JVM switches with which you start the
IDE, as outlined in the next section.
JVMs offer a variety of standard and non-standard switches that tune memory allocation and
garbage collection behavior. Some of these settings can benefit NetBeans IDE's performance.
Note that -X and especially -XX JVM switches are officially "unsupported" because they are often
JVM or JVM-vendor specific. The switches discussed in this section are available for Sun
Microsystems J2SE 1.4.2 and J2SE 1.5 - users of other JVM implementations may need to
remove these switches in order to run the IDE.
The following settings should produce better-than-factory setting performance on most systems.
With the exception of setting the "permanent area" size, these switches have been the defaults
for the IDE for some time, and should already be present in your netbeans.conf file.
● -J-Xverify:none - This switch turns off Java bytecode verification, making classloading
faster and eliminating the need for classes to be loaded during startup solely for the
purposes of verification. This switch improves startup time, and there is no reason not to
use it.
● -J-Xms32m - this setting tells the Java virtual machine to set its initial heap size to 32
megabytes. By telling the JVM how much memory it should initially allocate for the heap,
we save it growing the heap as the IDE consumes more memory.
● -J-Xmx128m - this setting specifies the maximum amount of memory that the the Java
virtual machine should use for the heap. Placing a hard upper limit on this number means
that the Java process cannot consume more memory than physical RAM available. This
limit can be raised on systems with more memory - the 128 megabyte setting helps to
ensure that the IDE performs tolerably on 256Mb systems. Note: Do not set this value to
near or greater than the amount of physical RAM in your system or it will cause severe
swapping during major collections.
● -J-XX:PermSize=20m - this is a more exotic JVM switch, but one which also improves
startup time. This setting sizes the "permanent area" of memory, where classes are kept.
Since we know that all of NetBeans IDE's classes take up a specific amount of memory, we
give the JVM a hint as to how much memory it will need. This setting eliminates major
garbage collection events during startup on many systems. Users of SunONE Studio or
other IDEs that include more modules may want to set this number higher.
Listed below are some additional JVM switches which have either anecdotally or measurably
impacted NetBeans performance on some, not all, systems. Your mileage may vary, but they
may be worth a try.
This section lists common tasks for application development, keyboard shortcuts for use in the
IDE, and abbreviations for coding in the Source Editor. For more detailed information, click the
links in the right column.
Keys Action
Tab Shifts focus to the next component or to the first member of the next
group of components (the upper-left component in left-to-right reading
order).
Shift-Tab Shifts focus to the previous component or to the last component in the
previous group of components (reverse navigation of Tab).
Down arrow Moves keyboard focus to the next item in a group of items.
Navigates to the next setting in a combo box in a property sheet.
Ctrl-Tab (Ctrl-') Toggles through the open windows in the order that they were last used.
The dialog box displays all open windows and each of the open documents
in the Source Editor.
Ctrl-F4 Closes the current tab in the current window. If the window has no tabs,
the whole window is closed.
Shift-F4 Opens the Documents dialog box, in which you can save and close groups
of open documents.
Add a JAR file to a standard project's 1. In the Projects window, right-click the Source
classpath. Packages node for the project and choose
Properties. The IDE opens the Project Properties
dialog box in the Compiling Sources page.
2. Click Add JAR and select the JAR file in the file
chooser.
Build a project. ● Choose Build > Build Main Project (F11) or right-
click any project node and choose Build Project.
Run a project. ● Choose Run > Run Main Project (F6) or right-
click any project node and choose Run Project.
Debug a project. ● Choose Run > Debug Main Project (F5) or right-
click any project and choose Debug Project.
Specify sources for a JAR file on the 1. Choose Tools > Library Manager from the main
project classpath. window.
2. If the JAR file is not already registered in the
Library Manager, create a new empty library
using the Add Library button.
3. Select the library in the left panel of the Library
Manager.
4. In the Classpath tab, click Add JAR/Folder and
specify the location of the JAR file containing the
compiled class files. A library can contain
multiple JAR files.
5. In the Sources tab, add the folder or archive file
containing the source code.
Specify Javadoc for a JAR file on the 1. Choose Tools > Library Manager from the main
project classpath. window.
2. If the JAR file is not already registered in the
Library Manager, register the JAR file as
described above.
3. In the Javadoc tab, click Add ZIP/Folder and
specify the location of the Javadoc files.
Set the main project. ● Right-click the project node and choose Set Main
Project.
VCS Tasks
Check out sources. 1. In the Versioning window, right-click the VCS working
directory's top level node and choose CVS > Checkout.
2. Specify the modules you wish to check out.
❍ To check out the entire repository select All.
❍ To check out a specific directory, click the Select button
to choose from a list of all of the modules in the
repository.
3. Click Finish to check out the files.
Update local file 1. Right-click the file's node that you wish to update.
versions. 2. Choose CVS > > Update.
Diff files. 1. Right-click the appropriate revision node in the Versioning
window.
2. Choose Diff Graphical from the contextual menu.
Commit local changes. 1. Ensure that your local copies of the files are up-to-date by
right-clicking and choosing CVS > Update before committing
your changes.
2. Right-click the files or directories you wish to commit and
choose CVS > Commit.
Merge revisions. 1. In the Versioning window, expand the file's node to reveal the
subnodes for each revision and branch.
2. Right-click the revision you wish to merge into your working
copy and choose Merge With Revision.
Configure global VCS 1. Choose Tools > Options, expand the Source Creation and
options. Management node, then select the Version Control Settings
node.
2. Edit the desired properties in the Option window's right pane.
Configuring Tasks
Configure general options 1. Choose Tools > Options from the main menu.
2. Select the option node for the properties you wish to
edit.
3. Specify the desired settings in the option's property
sheet.
Set the IDE's web browser 1. Choose Tools > Setup Wizard from the main menu.
2. In the wizard, select the desired browser from the Web
Browser combo box.
Configure proxy 1. Choose Tools > Setup Wizard from the main menu.
settings 2. In the wizard, select the Use HTTP Proxy Server check
box.
Configure the Auto Update 1. Choose Tools > Setup Wizard from the main menu.
feature 2. Advance to the Update Center page of the Setup wizard.
3. Specify the update check frequency and any options.
Install additional 1. Choose Tools > Update Center from the main menu.
modules 2. Designate the location of modules you want to install in
the Update Center wizard and click Next.
3. Select the modules you wish to install.
4. Review the licensing agreement and click Accept.
Customize the IDE's Menus 1. In the Options window, expand IDE Configuration
> Look and Feel.
2. Right-click the Menu Bar node and choose Add > Menu.
3. In the New Menu dialog box, type a name for the menu
and click OK.
Customize the IDE's Toolbars 1. Right-click the empty space in the toolbar area and
choose Customize Toolbars from the contextual menu to
display the Toolbars dialog box.
2. Right-click the Toolbars node and choose Add > Toolbar
to display the New Toolbar dialog box.
3. Type a name for the toolbar in the Name text field and
click OK.
Configure General Java 1. From the main menu, choose Tools > Options.
Settings 2. Expand the Editing node and select Java Sources.
3. Set properties as desired in the right pane of the
window.
Open a file that is not available 1. Choose File > Open File.
in the Projects window or the 2. In the file chooser, navigate to the file. Then click
Files window. Open.
Format code automatically. ● Right-click in the Source Editor and choose Reformat
Code.
Abbreviation Expansion
En Enumeration
Ex Exception
Ob Object
St String
ab abstract
bo boolean
br break
ca catch (
cl class
cn continue
df default:
ex extends
fa false
fi final
fl float
fy finally
ie interface
im implements
iof instanceof
ir import
pe protected
pr private
pst printStackTrace();
pu public
re return
st static
sw switch (
sy synchronized
tds Thread.dumpStack();
th throws
tw throw
wh While (
Source Editor Abbreviations for JSP and Servlet Files
Abbreviation Expansion
ag application.getValue("
ap application.putValue("
ar application.removeValue("
cfgi config.getInitParameter("
jg <jsp:getProperty name="
oup out.print("
oupl out.println("
pcg pageContext.getAttribute("
pcgn pageContext.getAttributeNamesInScope("
pcgs pageContext.getAttributesScope("
pcr pageContext.removeAttribute("
pcs pageContext.setAttribute("
pg <%@ page
rg <request.getParameter("
sg session.getValue("
sp session.putValue("
sr session.removeValue("
Abbreviation Expansion
!do <!DOCTYPE>
!cd <![CDATA[|]]>
pu PUBLIC "|"
sy SYSTEM "|"
pu PUBLIC "|"
sy SYSTEM "|"
cd CDATA
em EMPTY
en ENTITY
ens ENTITIES
fi #FIXED
im #IMPLIED
nm NMTOKEN
nms NMTOKENS
nn NOTATION
pc #PCDATA
Building Tasks
Add a JAR file to a project's 1. In the Projects window, right-click the Source
classpath. Packages node for the project and choose
Properties. The IDE opens the Project Properties
dialog box in the Compiling Sources page.
2. Click Add JAR and select the JAR file in the file
chooser.
Add an IDE project to a project's 1. In the Projects window, right-click the Source
classpath. Packages node for the project and choose
Properties.
2. Click Add Project.
3. Select the project directory for the required project.
Build a project. ● Choose Build > Build Main Project (F11) or right-
click any project in the Projects window and choose
Build Project.
Correct compilation errors. 1. In the Output window, double-click any Java syntax
error to jump to the location in the source code
where the error occurred.
2. In the Output window, double-click any Ant error to
open the Ant script in the target that failed.
Set the project main class 1. Right-click the project node in the Projects window
and choose Properties.
2. Click Running Project.
3. Type the fully qualified name of the class in the Main
Class field.
Set the runtime arguments. 1. Right-click the project node in the Projects window
and choose Properties.
2. Click Running Project.
3. Enter the arguments in the Arguments field.
Set the runtime classpath. 1. Right-click the project node in the Projects window
and choose Properties.
2. Click Running Project.
3. Add a JAR file, Java class library, or projectto the
project's classpath.
Set the working directory for 1. Right-click the project node in the Projects window
execution. and choose Properties.
2. Click Running Project.
3. Type the full path to the working directory in the
Working Directory field.
Run a project. ● Choose Run > Run Main Project (F6) or right-click
any project in the Projects window and choose Run
Project.
Run a single file. 1. Select one or more files in the Projects window, Files
window, or Source Editor.
2. Choose Run > Run Other > Run Classfrom the main
menu.
Set request parameters for 1. Right-click the JSP file in the Projects or Files window and
JSP files. choose Properties.
2. In the Request Parameters dialog box, type the
parameters in the URL_query_string format.
3. Click OK.
Set execution URIs and You can only set a request URI for a servlet if it has servlet
parameters for servlets. mappings in the deployment descriptor (web.xml file). Note that
the default URI is defined in the deployment descriptor.
Set the web server. 1. Right-click the project node in the Projects window and
choose Properties.
2. Click Running Project.
3. Select the web server from the server drop-down.
Set the context path and 1. Right-click the project node in the Projects window and
relative URL. choose Properties.
2. Click Running Project.
3. Type a context path and, optionally, a relative URL.
Run a project. ● Choose Run > Run Main Project (F6) or right-click any
web project in the Projects window and choose Run
Project.
Run a single file. 1. Select one or more files in the Projects window, Files
window, or Source Editor.
2. Choose Run > Run Other > Run Filefrom the main menu.
Debugging Tasks
Start a local debugging ● To debug the main project, choose Run > Debug Main
session. Project(F5).
● To debug any individual project, right-click the project
and choose Debug Project.
Start a remote debugging 1. On the computer where program is located, start the
session. program in debugging mode.
2. On the computer where the IDE is running, open the
projects that contain the source for the program.
3. Choose Run > Attach Debugger.
4. Select the connector type and enter any required
process information, then click OK. See your VM
documentation for information about the connectors it
provides.
Debug a single file. ● Select any runnable file in the Projects window and
choose Run > Run Other > Debug File.
Finish a debugging session. ● To finish the current session, choose Run > Finish
Debugger Session (Shift-F5).
● To finish any session, open the Sessions window (Alt-
Shift-6), right-click the session, and choose Finish.
Set a breakpoint. ● To set a line breakpoint, open the file in the Source
Editor and click in the left margin on the desired line.
● In the Source Editor, select the element of code on
which you want to set a breakpoint and choose Run >
New Breakpoint(Ctrl-Shift-F8). Then set the breakpoint
type and additional options in the New Breakpoint dialog
box.
Modify breakpoint properties. ● Open the Sessions window (Alt-Shift-6), right-click the
session, and choose Customize.
Step into JDK classes. ● Open the Sources window (Alt-Shift-8) and select the
checkbox for the archive file or directory containing the
JDK sources.
Manage which classes the ● Open the Sources window (Alt-Shift-8) and uncheck the
debugger steps into. checkbox for the source directories you do not want to
step into.
Pop a call from the call stack. ● To pop the most recent call from the call stack, choose
Run > Stack > Pop Topmost Call.
● To pop multiple calls, open the Call Stack window (Alt-
Shift-3), right-click the call that you want to remain at
the top of the call stack, and choose Pop to Here.
View information for a call on ● To move one level away from the main routine, choose
the call stack. Run > Stack > Make Callee Current (Ctrl-Alt-up arrow).
● To move one level toward the main routine, choose Run
> Stack > Make Caller Current (Ctrl-Alt-down arrow).
● To make a call current, double-click the call in the Call
Stack window.
JUnit Tasks
Create a test for existing 1. Right-click the class or package node for which you wish
sources. to generate a test.
2. Choose Tools > JUnit Tests > Create Tests (Ctrl-Alt-J)
from the contextual menu. Set the parameters for the
test skeleton generator in the Create Tests dialog box.
3. Click OK.
Create an empty test. 1. Choose File > New File.
2. Select JUnit in the Categories pane and Empty Test in
the File Types pane. Click Next.
3. Enter a name for the test class in the Class Name field.
4. Select the target package from the Package combo box
and set any required options.
5. Click Finish.
Run a test for a class. 1. Select the node of the class you wish to test.
2. From the Main Menu, choose Run > Run Other > Run
classname (Shift-F6).
Run tests for an entire 1. Select the node of the project for which you wish to run
project. tests.
2. From the contextual menu, choose Test Project (Alt-F6).
Edit a test. 1. Right-click the node for the source whose test you wish
to edit.
2. Choose Tools > JUnit Tests > Open Test (Ctrl-Alt-K)
from the contextual menu.
Debug a test. 1. Select the class for whose test you wish to debug.
2. Choose Run > Run Other > Debug Test for File (Ctrl-
Shift-F6).