First experiences and getting started with GlassFish 3.1 and NetBeans 7.x – it's a breeze

2

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

Download software

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.

Image

Install software

Installation instructions can be found at http://netbeans.org/community/releases/70/install.html

Image

In my case, installation meant running the installer.

Image

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.

Run NetBeans

The installer had created a program group from where I can start NetBeans:

Image

Alternatively run the NetBeans executable.

Image

The launch screen:

Image

Then the NetBeans IDE opens.

Image

Activate plugins

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.

Image

I have activated the plugins for Java SE, Java Web and EE and Web Applications and subsequently restarted NetBeans.

Image

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.

Image

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.

Image

From the context menu on the GlassFish Server 3.1 node, we can start the server:

Image

The server is started. The output produced by GlassFish as it is starting up is displayed in the Console Window:

Image

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:

Image

The browser window opens, displays an intermediate message

Image

and then shows the console – at URL http://localhost:4848/common/index.jsf:

Image

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

Image

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:

Image

Browse for the war file downloaded earlier on for the demo application. Then press the OK button to start deployment of the war file:

Image

When deployment is complete, this page appears with an overview of all deployed applications:

Image

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:

Image

Click on the first link and the application itself opens:

Image

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:

Image

Choose Java Web as Project Type. Press Next.

Image

Specify the name and a directory for the project.

Image

Then press Next.

The defaults on step 3 are fine, so just press next.

Image

In step 4, select JSF as framework to configure in the new Web Application.

Image

Then press Finish to have the project generated by NetBeans.

The following project structure is created, including the index.xhtml file:

Image

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:

Image

The following output is produced in the console window:

Image

The browser is opened and the web application output appears:

Image

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:

Image

then save the changes.

Image

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:

Image

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.

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

2 Comments

  1. Pingback: Installing Tomcat 7 and Configuring as Server in NetBeans « AMIS Technology blog

Leave a Reply