First experiences and getting started with GlassFish 3.1 and NetBeans 7.x – it's a breeze
Several years back, AMIS selected GlassFish as its preferred Open Source J(2)EE Application Server, over for example JBoss. Some of the criteria at the time were: speed of implementation of new functionality and integration of JEE (being the reference implementatoin), ease of administration, enterprise quality, small yet rapidly growing market share (the band wagon to hop onto). The fact that now GlassFish is under Oracle’s wings and heavily invested into has further underlined our selection.
During these past few years, I have not had a lot of hands-on experience working with GlassFish. Apart from attending sessions and HOLs (hands-on labs) at JavaOne, reading articles on internet and in general staying updated on the developments around GlassFish, unlike some of my colleagues at AMIS I did not touch the software myself.
Today that changed. I had some time on my hands, an interest in working with WebSocket support in GlassFish and a desire to finally work on the product for myself. This article is a report on my first steps. What I had to do in order to get my first web application running after getting hold of the software and installing the product. It is short and very straightforward, as it is dead-easy to get started. I really like that!
So based on my experiences, I can only recommend that you give it a spin yourself. It should not take you longer than 45 minutes to get GlassFish 3.1 set up, along with NetBeans 7.x, and start a sample web application as well as create and run your own web application.
The steps are familiar, I am sure:
- download software (bundle with GlassFish 3.1 and NetBeans 7.x)
- run installer (in my case on Windows but the same applies to Linux and presumably MacOS)
- run NetBeans
- activate plugins in NetBeans to initialize support for Java SE, EE and Web Applications
- start GlassFish server from within NetBeans
- open GlassFish Administration Console
- get hold of demo web application (war-file)
- deploy demo war-file from Administration Console
- launch demo application
- create ‘my first’ JEE (JSF) Web application in NetBeans
- run ‘my first’ web application from NetBeans (on GlassFish)
- change ‘my first’ web application and inspect modifications
I downloaded from http://netbeans.org/downloads/start.html?platform=windows&lang=en&option=all the bundle NetBeans 7.0.1 Installer for Windows(244 MB) with NetBeans and GlassFish included.
Installation instructions can be found at http://netbeans.org/community/releases/70/install.html
In my case, installation meant running the installer.
The installer needed to a reference to a Java 6 JDK installation. It also asks for target directories to install into, for both NetBeans and GlassFish. The installer prompted me to accept a number of license agreements for bundled products, such as JUnit. I happily accepted these. Otherwise, I ran it with only defaults.
The installer had created a program group from where I can start NetBeans:
Alternatively run the NetBeans executable.
The launch screen:
Then the NetBeans IDE opens.
Even though the downloaded bundle contained GlassFish, support for JEE (or even Java SE for that matter) is not automatically enabled in NetBeans. Some of the installed plugins need first to be activated in order for the NetBeans IDE to “spread its Java and JEE wings”.
From the Tools menu, choose the Plugins option.
I have activated the plugins for Java SE, Java Web and EE and Web Applications and subsequently restarted NetBeans.
Start GlassFish server from within NetBeans
The GlassFish 3.1.x server that was installed along with NetBeans is preconfigured in NetBeans. It can easily be started from within the IDE. JEE (Web) Applications can be ran from within NetBeans and automatically deployed to GlassFish and launched in an external browser.
In NetBeans, open the Window menu and select the option Services (or use the key combination Ctrl + 5.
The window with Services opens. It lists among other things the Servers that have been configured in NetBeans. The GlassFish 3.1 server that was pre-installed and pre-configured is already there.
From the context menu on the GlassFish Server 3.1 node, we can start the server:
The server is started. The output produced by GlassFish as it is starting up is displayed in the Console Window:
Open GlassFish Administration Console
The Administration Console for GlassFish is accessible from a browser. It can be launched from within NetBeans, using the same context menu that was used to start the server:
The browser window opens, displays an intermediate message
and then shows the console – at URL http://localhost:4848/common/index.jsf:
Get hold of demo web application
A simple demo web application that we can quickly use to verify the installation of GlassFish and our initial grasp of the Administration Console is available from http://docs.oracle.com/cd/E18930_01/html/821-2432/geyvr.html#ghgis
Download the WAR-file and save it somewhere locally on your file system.
Deploy demo war-file from Administration Console
Click on the button Deploy an Application:
Browse for the war file downloaded earlier on for the demo application. Then press the OK button to start deployment of the war file:
When deployment is complete, this page appears with an overview of all deployed applications:
Deployment was very fast – compared to my experiences with other application servers!
Launch demo application
The basic operations available for all deployed applications are accessible from this page – undeploy, enable and disable, reload (re-start) and launch. When you click the Launch link, the following popup appears from which the web application can be started:
Click on the first link and the application itself opens:
Create ‘my first’ JEE (JSF) Web application in NetBeans
The steps for creating and running a very simple web application in and from NetBeans are very straightforward as well. From the File menu choose New Project:
Choose Java Web as Project Type. Press Next.
Specify the name and a directory for the project.
Then press Next.
The defaults on step 3 are fine, so just press next.
In step 4, select JSF as framework to configure in the new Web Application.
Then press Finish to have the project generated by NetBeans.
The following project structure is created, including the index.xhtml file:
Run ‘my first’ web application from NetBeans (on GlassFish)
Running a web application on the pre-configured GlassFish server is as simple as right click on the index.xhtml file and selecting the Run File option:
The following output is produced in the console window:
The browser is opened and the web application output appears:
Change ‘my first’ web application and inspect modifications
Changes in the web application can quickly be redeployed and inspected in the browser. For example, add a few exclamation marks in the index.xhtml file:
then save the changes.
Saving the file will prompt NetBeans to automatically redeploy the web application. When I next refresh the browser window, I will see the effect of the changes:
Now I am ready for more NetBeans and GlassFish explorations. Especially WebSockets and Grizzly are on my agenda – although these seem to be not as trivial as what I have shown in this article.
- Combining Hibernate and Facelets with Maven, Netbeans and GlassFish
- Integrating Seam with Maven, Netbeans and GlassFish
- Getting Started with EJB 3.0 Persistence out-of-container using the Reference Implementation (GlassFish)
- Getting started with the EJB 3.0 Query Language (EJBQL 3.0) using GlassFish reference implementation
- GlassFish and OpenESB session – brief report including download presentation resources
Didn't find any related posts :(