Book Image

Java EE 6 with GlassFish 3 Application Server

By : David R Heffelfinger
Book Image

Java EE 6 with GlassFish 3 Application Server

By: David R Heffelfinger

Overview of this book

<p>GlassFish is a free, open source, production ready application server. It is the environment's reference implementation and the first Enterprise Java server to implement Java EE6. Although GlassFish server delivers a flexible, lightweight and extensible Java EE 6 platform, it can be challenging to get beyond the basics and develop Java applications deployed to GlassFish 3 application server.<br /><br />This book takes an in-depth look at all of the major new features in Glassfish 3 and how it differs from previous Glassfish versions. This book explains GlassFish installation and configuration, and then moves on to Java EE 6 application development, covering all major Java EE 6 APIs. It is a handy guide for the advanced Java programmers as well as Java EE 6 beginners.<br /><br />This book begins with the installation of Glassfish 3 and deploying Java applications. It also explains how to develop, configure, package and deploy servlets. We will also learn the processing of HTML Forms. As we move on, we will develop Java Server Pages and get to know implicit JSP objects. We will get to know all the JSTL (JSP Standard Tag Library) tag libraries. This book gives us a better understanding on how to manage data from a database through Java Database Connectivity (JDBC) API and the Java Persistence API (JPA). We will also learn more about the newly introduced features of JPA 2.0 and develop JSF 2.0 applications learn how to customize them. We then set up Glassfish for Java Messaging (JMS) API and understand the working of message queues and message topics. Later, we use the Context and Dependency Injection (CDI) API to integrate application layers and study the SOAP based web service development using the JAX-WS specification. Finally, we learn more about the Restful web service development using the JAX-RS specification.<br /><br />The book covers the various Java EE 6 conventions and annotations that can simplify enterprise Java application development. The latest versions of the Servlet, JSF, JPA, EJB and JAX-WS specifications are covered, as well as new additions to the specification such as JAX-RS and CDI.</p>
Table of Contents (20 chapters)
Java EE 6 with GlassFish 3 Application Server
Credits
About the Author
About the Reviewers
Preface
IDE Integration
Index

Eclipse


Unlike NetBeans, Eclipse does not come with GlassFish support out of the box. Fortunately, it is very easy to add GlassFish support. Eclipse can be downloaded from http://www.eclipse.org.

Note

In this section, we assume that the Eclipse IDE for Java EE developers is installed. This version of Eclipse includes tools for Java EE (JSF, JPA, EJB, and so on) development.

In order to integrate Eclipse and GlassFish, we need to download the GlassFish server adapter for Eclipse. To do this, we need to right-click on the Servers tab at the bottom of the Java EE perspective and select New | Server:

We then need to click on the Download additional server adapters link in the window that pops up:

After doing so, a list of all available server adapters will be shown:

We simply need to select GlassFish and click on the Next > button.

At this point, we need to accept the license agreement and click Finish.

After the GlassFish server adapter for Eclipse is downloaded, we are told that it is strongly recommended to restart Eclipse. It is a good idea to do so.

After Eclipse restarts, the GlassFish server adapter is fully installed, and we are ready to deploy our applications to GlassFish straight from Eclipse.

To demonstrate the integration between GlassFish and Eclipse, we will use a project of type Dynamic Web Project, but the procedure is very similar for other Java EE project types.

To create a new Dynamic Web Project, all we need to do is click on File | New | Dynamic Web Project.

When creating a Dynamic Web Project, Eclipse will ask, among other things, for the Target runtime for the project. The target runtime is "Eclipse Speak" for a Java EE application server.

To select GlassFish as our target runtime, we need to click on the New... button, then select GlassFish v3 Java EE 6 from the GlassFish folder.

After clicking Next >, we need to indicate the directory where GlassFish is installed:

We then need to indicate the domain directory, name, administrator Id, and password for our domain. Most of these fields have sensible defaults. In most cases, the only field we need to enter is the password.

After we finish creating our project, we should see GlassFish in the Servers view, which is typically at the bottom of the screen:

If the Servers view is nowhere to be seen, it can be opened by clicking on Window | Show View | Servers.

At this point, we are ready to start developing our application. When we are at a point where we need to deploy it, we can do so by clicking on the GlassFish server icon in the Servers view and selecting Publish:

At this point, Eclipse will build, package, and deploy the application.

For web applications, we can execute the application as soon as it is deployed by right-clicking on the project and selecting Run As | Run on Server:

At this point, Eclipse will build, package, deploy the application, and open it in a browser window embedded in Eclipse.

If we wish to debug the application using Eclipse's debugger, we can do so by right-clicking on the project and selecting Debug As | Debug on Server. This will cause Eclipse to start or restart GlassFish in debug mode, if necessary, and deploy the application. We can then debug it using Eclipse's built-in debugger.