The following steps describe how to set up your development environment. In the process, you'll learn about some of the primary windows of the IDE and understand how the IDE uses an Ant build script to perform common actions on your project. By the end of this tutorial unit, you'll have created a web application project, and confirmed that you can successfully build the project, deploy it to your development server, and run it from the IDE.
You also learn how to connect the IDE to a MySQL database server, create database
instances, and connect to database instances from the IDE's Services window. In
this unit, you create a new database named
affablebean, which you
will use throughout the tutorial.
You can view a live demo of the application that you build in this tutorial: NetBeans E-commerce Tutorial Demo Application.
|Software or Resource||Version Required|
|NetBeans IDE||Java bundle, 6.8 or 6.9|
|Java Development Kit (JDK)||version 6|
|GlassFish server||v3 or Open Source Edition 3.0.1|
|MySQL database server||version 5.1|
AffableBean. In this step, you can also designate the location on your computer where the project will reside. By default, the IDE creates a
NetBeansProjectsfolder in your home directory. If you'd like to change the location, enter the path in the Project Location text field.
If you wanted to deploy to a server that isn't yet registered with the IDE, you would click the Add button, and step through the Add Server Instance wizard. You can view all servers registered with the IDE from the Servers window (Choose Tools > Servers from the main menu).
AffableBeanthat adheres to the J2EE Blueprints conventions for web application structure. The IDE displays various windows in its default layout.
Configuration Files). When right-clicking file nodes within the Projects window, you can call actions common to your development tasks (i.e.,
build.xml), and files required by the IDE to handle the project (contained in the
nbprojectfolder). If you've run your project, you can see the location of compiled Java files (
buildfolder). If you've explicitly built your project (by choosing Build, or Clean and Build, from the project node's right-click menu in the Projects window), you can view the project's distributable WAR file (contained in the
TODO' or '
Clean and Build,
Note: All of the IDE's windows can be accessed from the Window menu item.
AffableBeanproject. In the Projects window, you can do this by right-clicking the project node and choosing Run, otherwise, click the Run Project ( ) button (F6; fn-F6 on Mac) in the IDE's main toolbar.
runAnt target in your project's build script. You can investigate by opening your project's
build.xmlfile in the editor.
build.xmlfile contained in your project. When the
build.xmlfile opens in the editor, the Navigator lists all Ant targets available to the script.
Normal Ant targets are displayed using the general target ( ) icon. The emphasized Ant target ( ) icon merely indicates that the target includes a description, which is displayed as a tooltip (as shown in the above image). For more information, see Creating, Importing, and Configuring Java Projects.
build-impl.xmlfile opens in the editor and displays the target definition.
<target depends="run-deploy,run-display-browser" description="Deploy to server and show in browser." name="run"/>Why did the
build-impl.xmlfile open when we clicked on a target from
build.xml? If you switch back to
build.xml(press Ctrl-Tab) and examine the file contents, you'll see the following line:
The project's build script is basically an empty file that imports NetBeans-defined
You can freely edit your project's standard
script by adding new targets or overriding existing NetBeans-defined targets.
However, you should not edit the
runtarget's definition that it depends on the following targets:
build-impl.xmlfile. But essentially, the following actions take place when the
runtarget is invoked:
Consult the official Ant Manual for more information on using Ant.
distfolder contains the project WAR file. The
buildfolder contains your compiled project.
Note: If you clean the project (In the Projects window, choose Clean from the project node's right-click menu), both of these folders are removed.
Note: "GlassFish v3" is the default server name for NetBeans 6.8 users.The green arrow icon on the GlassFish server node ( ) indicates that the server is running. The Applications folder lists all deployed applications; you can see that the
AffableBeanapplication has been successfully deployed.
At this stage, you've created a Java web project in the IDE, and have confirmed that it can be successfully built and deployed to your development server, and opened in a browser when run.
Once you've downloaded and installed the MySQL database server, you can connect to
it from the IDE. A default installation uses '
root' and '' (an empty
string) as the user account and password to connect to the database server. However,
due to connectivity issues with GlassFish, it is recommended that you use an account
with a non-empty password.
The following instructions demonstrate how to run the database server
and change the password for the
root account to '
from the MySQL command-line. The '
root' / '
combination is used throughout the NetBeans E-commerce Tutorial. With the database
server running and properly configured, you register it in the IDE and create a
Note: The command-line instructions below assume that
you have added the
mysql command to your
variable. (If you haven't, you'll receive a '
mysql: command not found'
error when entering
mysql commands in your command-line.)
If you haven't added
mysql to your
PATH, you can instead
call the command by entering the full path to your MySQL installation's
directory. For example, if the
mysql command is located on your computer
/usr/local/mysql/bin, you would enter the following:
shell> /usr/local/mysql/bin/mysql -u root
For more information, see the offical MySQL Reference Manual:
Perform the following steps.
Before connecting to the MySQL server from the IDE, you need to make sure the
server is running. One way to do this is by using the
shell> mysqladmin pingIf the server is running, you will see output similar to the following:
mysqld is aliveIf the server is not running, you'll see output similar to the following:
mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
In the event that your MySQL server is not running, you can start it from the command-line. See 220.127.116.11. Starting and Stopping MySQL Automatically for a brief, cross-platform overview. The following steps provide general guidance depending on your operating system.
For Unix-like systems, it is recommended to start the MySQL server by invoking
shell> sudo ./mysqld_safeYou will see output similar to the following:
090906 02:14:37 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
The MySQL Windows installer enables you to install the database server as a Windows
service, whereby MySQL starts and stops automatically with the operating system.
If you need to start the database manually, run the
command from the installation directory's
cmdin the text field). A command-line window displays.
C:\> "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld"
For more information, refer to the official MySQL Reference Manual: 18.104.22.168. Starting MySQL from the Windows Command Line.
To set the
root account's password to '
the following steps.
shell> mysql -u root mysql> UPDATE mysql.user SET Password = PASSWORD('nbuser') WHERE User = 'root'; mysql> FLUSH PRIVILEGES;
For more information, see the official MySQL Reference Manual: 2.13.2. Securing the Initial MySQL Accounts.
The IDE's Services window enables you to connect to the server, start and stop the server, view database instances and the data they contain, as well as run an external administration tool on the server.
mysqld_safe, depending on your operating system. (See Start the Database Server above.)
Note: For Unix-like systems, you may find that you can only invoke the start command with root or administrative privileges. To overcome this, you can create a script (using GKSu for Linux and Solaris, osascript for Mac) that will accomplish this task. For more information, see this blog post.
mysqladmin shutdown). Because the command requires a user account with shutdown privileges, you must enter username/password credentials in the Arguments field. For example:
-u root -pnbuser shutdown
After you have set the fields listed under the Advanced Properties tab, you can:
affablebean. Select the 'Grant Full Access to' option, then select
root@localhostfrom the drop-down field. This enables the
rootaccount on the
localhosthost access to the database. Later, when you create a connection pool on the server, you'll need to provide the
nbuserpassword as username/password credentials in order to grant the server access to the database.
affablebeanis created, and a connection to the database is automatically established. Connections are displayed in the Services window using a connection node ( ).
Note: Connection nodes are persisted in the Services window. If you restart the IDE, the connection node displays with a jagged line ( ), indicating that the connection is broken. To reconnect to a database, make sure that the database server is running, then right-click the node and choose Connect.
affablebeandatabase. The connection contains the database's default schema (
affablebean), and within that are nodes for tables, views, and procedures. Currently these are empty since we haven't created anything yet.
At this stage, you've connected to the MySQL server from the IDE and have created
a new database named
affablebean which you'll use throughout the tutorial.
Also, you've created a Java web project in the IDE, and have confirmed that it can be
successfully built and deployed to your development server, and opened in a browser
when run. Now that your development environment is ready, you can begin drafting the
application's data model.