|
I talked about installing glassfish to do some Java EE development. Today, I
am going to describe NetBeans IDE installation. I am going to use
NetBeans because it supports Java EE development and works well with glassfish
server (which implements the Java EE specifications). Installing NetBeans IDE
is no rocket science (in fact, it's not even science), just remember to have
JDK 5.0 installed on your machine and while downloading select NetBeans v5.5 beta as earlier
versions don't support Java EE.
Prerequisites
You must have downloaded and installed JDK 5.0 before installing glassfish.
You can download JDK 5.0 from http://java.sun.com/javase/downloads . You
must also set JAVA_HOME environment variable to point to the jdk installation
directory. For example, on my machine, I have installed jdk in C:\MySoftware\jdk1.5.0_07
so my JAVA_HOME points to C:\MySoftware\jdk1.5.0_07. It is also
recommended that you add the following entry in the PATH variable: %JAVA_HOME%\bin.
Download and installation
Go to http://www.netbeans.info/downloads/download.php?type=5.5b , choose your
operating system and language (the instructions here are for Windows), download NetBeans
IDE 5.5 Beta Installer, double click exe, choose installation path, select
JDK home directory (if you have multiple JDKs installed, all of them will show up), review the summery and click next to start the
installation. Plain and simple! Just remember that the uninstaller is at
<netbeans_home>/_uninst/uninstaller.exe.
Configuration
Installation was easy. Now we need to tell NetBeans about GlassFish so that
we can deploy projects, test them and administer the server from the IDE.
Configuring GlassFish server is as easy as adding a server, selecting its type
and pointing NetBeans to the <server_home> directory. NetBeans figures
out everything else. To configure glassfish in NetBeans,
- Go to Tools > Server
Manager

- You should see bundled Tomcat
server already configured
- Click on Add Server
- From the drop down, choose
Sun Java System Application Server and give it a name glassfish. GlassFish
is an open source version of Sun Java System Application Server so this
selection will work. Next, we will point NetBeans to GlassFish location.
Click Next

- If NetBeans has not picked
the values automatically, enter <glassfish_home> for Platform
Location and select the domain under Register Local Default Domain. Refer to GlassFish installation instructions for more
information. Click Next
- Enter admin username and
password and click Finish
- You should see GlassFish configuration as shown
below. Close this dialog box
Testing installation
We will create a very simple web application to make sure NetBeans/GlassFish
configuration is correct and working. Our simple application will ask you to
enter your name and display a "Hello" message. To
create and run the application, we will simply create a new web application
selecting the right server and Java EE version, code 2 JSPs and run the
application.
- Select File > New Project
- Choose Web category and Web
Application project and click Next
- Enter and name and the
location of the project. I have created an NBWorkspace directory to act as
a workspace for all NetBeans projects. Select other options and enter
values as shown. Remember to select glassfish server and Java EE 5
as server and J2EE version respectively. Click Next
- This simple application will NOT need Struts or JSF support so make sure they are both deselected.
Click Finish
- This creates a sample web
application with all necessary files and directories as shown
- Right click index.jsp and select Copy
- Right click Web Pages directory and select Paste
- Right click newly created index_1.jsp and rename it to hello.jsp
- index.jsp will have a text box to type your name and a submit button and hello.jsp will have the greetings
- Open index.jsp and insert the following code in it (delete the existing content before inserting this code):
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
</head>
<body>
<h1>Welcome</h1>
<form action="hello.jsp">
Please enter your name:
<input type="text" name="name"><br>
<input type="submit">
</form>
</body>
</html> |
- Open hello.jsp and insert the following code in it (delete the existing content before inserting this code):
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Greeting</title>
</head>
<body>
<h1>Hello <%= request.getParameter("name") %></h1>
<br>
<a xhref="index.jsp">Back</a>
</body>
</html>
|

- Right click the project sample and select Run Project. This will start the server, deploy your application and run it. If you get a warning message "Java DB location not set correctly," ignore it for now. We will worry about setting DB location later
- When the server is running and application is deployed, you should see the following page
- Enter your name and click Submit Query and you should see the following page
- Back in NetBeans, you should see a glassfish tab in output view, you can use this tab to stop/start the server
Conclusion
We installed glassfish in the previous article. Today, we saw how to install NetBeans and configure it to use glassfish. We also created a sample application to validate the configuration. I highly recommend playing with NetBeans. Try creating a Struts application and see how NetBeans works.
|