Create a Java EE Web Application using the Glassfish Server

By Rob Gravelle

https://www.htmlgoodies.com/beyond/java/create-a-java-ee-web-application-using-the-glassfish-server.html (Back to article)

Create a Java EE Web Application using the Glassfish Server

Not long after Java first released Java Beans, rumblings began about how darn complicated it was to implement. I remember learning it in School and the instructor practically pulled his hair out trying to get it to work! Soon after, the Spring Framework was introduced to ease our pain. For a while, you'd be hard pressed to find anyone developing Enterprise level applications without it. Of course it wasn't a perfect solution either. Spring depends a lot on XML files which can quickly become very large and unwieldy. Now, Oracle, the makers of Java, have fought back with the EJB 3.1 spec. It's more lightweight that Spring and adheres more closely to the convention over configuration principle, whereby the number of decisions that developers need to make is decreased in order to gain simplicity. In today's article we'll discover what makes an Enterprise Application and learn how to create a Java EE application project and configure a Glassfish server in the ever-versatile Eclipse IDE.

Java EE vs. Java SE

A lot of developers don't realize that Java comes in several different flavors, including:

If you've ever used Java before, I would be willing to bet that it was the SE version. (If you haven't, you may want to learn the basics of the language before trying to follow this tutorial because Enterprise Java is an advanced topic.) Built on top of the Java SE platform, Java EE provides an API and runtime environment for developing and running large-scale, multi-tiered, scalable, reliable, and secure network applications. In other words, industrial-strength apps!

What You'll Need

For this tutorial you will need the following software:

The tutorial was written using Eclipse Luna but it should work with other Eclipse versions as well. Dialog boxes and menus might look slightly different but the code should be exactly the same.

Components of a Java EE Application

Before you fire up Eclipse, let's get a bird's eye view of the components that make up a Java EE application, since we'll have to put each of these in place to get our project off the ground.

A Java EE application, going from the "back" to "front" end, consist of the four following parts:

  1. Persistence Unit and Models: A data store and classes that represent each data entity. Part of the the Enterprise Information System (EIS) tier, the data store may in fact include enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems.
  2. EJB Session Beans: Special classes that manage specific business transactions and processes.
  3. Servlet: A small Java program that runs within a Web server. The Servlet receives and responds to requests from Web clients, made via HTTP or SHTTP.
  4. JSP Page: A special kind of Web page that may contain server-side scripts.

Java EE application

We'll be covering each in more detail as we implement them.

Creating a Java EE Project in Eclipse

Now it's time to start Eclipse!

The Web application that we'll be creating manages a collection of fitness exercises - something that all of us desk jockeys are in dire need of! New exercises may be added using a basic HTML form. All of the stored exercises are listed below the input fields.

Setting the Target Runtime

The Target runtime field is where you designate the server to which you'll be deploying your Web project.

Conclusion

In the next article, we'll set up the database and code our application.


Rob Gravelle resides in Ottawa, Canada, and is the founder of GravelleWebDesign.com. Rob has built systems for Intelligence-related organizations such as Canada Border Services, CSIS as well as for numerous commercial businesses.

In his spare time, Rob has become an accomplished guitar player, and has released several CDs. His band, Ivory Knight, was rated as one Canada's top hard rock and metal groups by Brave Words magazine (issue #92).