Skip to main content

Introduction to Java EE application development

Hi, this is the first blog of series Java EE application development that I’m going to write. This series of tutorials will begin with a simple Notebook application with simple Java EE technologies and then move on to a complete and fully-implemented Java EE Notebook with JPA, CDI, Web Services, JMS etc. integrated. Sounds Cool? Let’s started!

Introduction

At first, Let me give you a brief interpretation of what Java EE is. The full name of Java EE is Java Enterprise Edition. In comparison with Java SE, the Java Standard Edition, the Java EE platform is designed to help developers create large-scale, multi-tiered, scalable, reliable, and secure network applications[1]. A typical Java EE application has three tiers, client tier, business/service tier and resource/data tier.

Java EE applications need a container as its runtime environment. The container is an implementation of Java EE APIs. As you may know, in the hardware industry, nvidia defines a series of specifications which each vendor can used it to produce their own product and they all have a unified interface, for example, PCI-E. This can apply to the software industry,
while Java EE is a suit of specifications, Glassfish, Wildfly, Weblogic, Websphere are the implementations of those specifications. As a result, it is actually the containers provide the function to run a Java EE application, not Java EE itself. Although Glassfish is the official implementation of Java EE, this tutorial is going to use Wildfly as application container, but don’t worry, they all function the same. Let’s go on to our coding phase!

Your First Java EE Application

Tools you will need

Eclipse

I assume you have already installed Java SE so that we can run eclipse on it.

Go to http://www.eclipse.org/downloads/eclipse-packages/ and download Eclipse IDE for Java EE developers. Extract the file where as you wish.

download eclipse

 

Wildfly

Download wildfly from http://wildfly.org/downloads/ , at the time of this blog is writing, the version is 10.1.0 final, choose the Java EE7 Full & Web Distribution. Unzip it after downloaded.

download Wildfly

Configure Eclipse

Select Servers tab at the bottom pane of Eclipse, click the link: No servers are available. Click this link to create a new server…

Configure Server 1

In the Define a New Server dialog, select Red Hat JBoss Middleware, then select JBoss AS, WildFly & EAP Server Tools.

Configure Server 2

Next, you will be prompted to download this connector, accept the license, click finish.

Configure Server 3

If you receive a warning like this,

Configure Server 4

clinick OK, then a restart dialog appears, click yes to take effect.

Configure Server 5

After eclipse restarted, repeat the step to add a server, this time you will see a list of servers under Red Hat JBoss Middleware. Select WildFly 10.x and click next.

Configure Server 6

In the create a new Server Adapter page, just keep the default value and click next.

configure server

Create a new JBoss Runtime, the home directory is where you unzipped wildfly package and Runtime JRE is your JDK installed.

configure server

Create a JSF project

The source code can be found here: https://github.com/zxuqian/Learning-Java-EE-2016/tree/master/zxuqian/notebook

We will use maven to manage our project dependencies and build processes. Maven is a very popular build tool for Java projects. You can manage libraries, build configurations with only a few xml codes.

First, let us create a dynamic web project, we will convert it to a maven project later. In the Project Explorer, right click and select New, in the sub-menu, select Dynamic Web Project.

creating JSF

Give the project a name, here is “notebook”. In the New Dynamic Web Project dialog, click Modify… button of the Configuration field.

creating JSF

Check the JavaServer Faces which will enable JSF facets to our project. Click OK to close this dialog, then click next.

creating JSF

check Generate web.xml deployment descriptor, this will allow us to configure JSF servlet to match URLs. Click finish.

creating JSF

Now let’s convert the project into a maven project. Right click the project, select Configure -> Convert to Maven Project.

convert to Maven

Fill the group id which may be your domain name or what else looks like a domain, and the artifact id can be your project name. The group id plus artifact id and version should uniquely identify your project in the Maven Repository if you publish it to the remote one. Click finish.

convert to Maven

It will be automatically converted to a maven project and generates a pom.xml which is the central part of Maven build configuration.

The pom.xml looks like

pom.xml

In the web.xml file, you don’t have to know the configuration, I will explain it when we study Servlet.

web.xml

The Welcome-file tag is to define the default page when you access your context root without specifying a page.  The servlet configuration means that every url matches /faces/* will be processed by JSF FacesServlet. Now let us make some modification, we will just need one welcome-file which will be named index.xhtml which .xhtml is suggested post fix by JSF. Then update url-pattern to *.xhtml that will match all url end with .xhtml. The web.xml now looks like:

web.xml

Let’s create our first page. At the WebContent folder, create a HTML File. Give it a name, index.xhtml, click next.

create html

From the HTML template combo box, select New XHTML (1.0 transitional) which is a relatively strict mode to write HTML. No serious HTML grammar mistake is allowed, such as only a begin tag, but no end tag. This format is also required by JSF. Then, click finish.

create xhtml

In this newly created web page, we import two namespaces, http://xmlns.jcp.org/jsf/html and http://xmlns.jcp.org/jsf/core, a JSF-HTML tag library and JSF core tag library. In this example, we just use the JSF-HTML tag library, which is almost the same as original HTML tags but with a h: prefix. It has other usages of course, but I will explain it in the future.

Write some sample tags like this:

index.xhtml

Then, our first code is done. It is a very simple project, but you should have learned some basic Java EE knowledge and how to create Java EE projects. Now lets run our project to see the result. First right click our project, select Run As->Maven install, this will let maven download dependencies and build our project into a war file which in turn be deployed to Wildfly.

run maven install

After building successfully, Right click the project and select Run As-> Run on Server.

Run on Server

In the dialog, choose Wildfly 10.x, you can always run the project in this server. The project will be deployed automatically.

choose server

After the server starts successfully, open a web browser, type the url: http://localhost:8080/notebook or http://localhost:8080/notebook/index.xhtml. The index.xhtml is not necessary because we have defined it in the welcome-file list in web.xml file.

The final result

result

 

Conclude

So far, you have learned what Java EE is and how to create a simply project using several tools. In the following blogs, we will focus on some coding until we begin to study other type of Java EE applications like JPA or Web Services.

 

 

 

 

 

 

 

  • 6666666

    • zxuqian

      23333

  • cz

    犀利!乾神再接再厉👍

    • zxuqian

      ..必须哒。。应该用英语评论。。 😀

  • haoFei

    Nice introduction and tutorial.

    • zxuqian

      Thank you!

  • lee

    wow,it’s really useful!xD

    • zxuqian

      Thank you! 😄

  • CHINARAIN

    Nice topic to share your knowledge about JEE!

    A side comment, for me, I’d like to introduce tech terms as little as I can tell one thing clearly, if you have to, make note to let your readers know that which is essential for current tutorial and which isn’t.

    • zxuqian

      Advice accepted!

  • TommyCliy

    Great article, help alot

    • zxuqian

      Thank you! 😀

  • Jiawen Peng

    wow, so great! I’m learning Java EE and your blog helps a lot!