Java EE Web Profile (EJB) quickstart tutorial with Maven, Intellij and Glassfish

Updated: 2012-09-30

This short tutorial has the goal to show how to start as fast as possible a new EJB project using IntelliJ and Maven.

  1. Create a new project from scratch

  1. Complete the form, you have to choose the Maven module

  1. Complete the Maven information

  1. Your project is created according to Maven standards

  1. Add Java EE dependencies, this step is necessary to create a Web Profile project, Intellij will download automatically the new artifact

We have to define the type of packaging we want in our maven config. Without declaring a packaging of type war the application won’t be deployed.

  1. Create a new Class, this class is of type Stateless (a Service for who comes from Spring)

  1. Edit the class, we do something very easy: a classical HelloWorld bean.

With the EE web profile we don’t need to create interfaces if we don’t access the stateless bean (service) from a different JVM.

  1. We create our web configuration. Add a web.xml file under WEB-INF

  1. The web.xml file is quite traditional, you can use one of the many templates on the web

  1. We can create now the managed bean, it’s the controller who manage the communication between the View (jsp) and the Model (EJB)

  1. The code of the controller is simple. The class is declared as @ManagedBean to allow the injection in the view. The EJB (Stateless class) is injected using the annotation. The getText method is exposed to the view.

  1. We can now create facelets page

  1. We call the view Hello.xhtml and we place it in the main webapp folder

  1. The interesting part of the code is the call to the helloMB managed bean. The @ManagedBean annotation previously used allow us to access easily to the bean.

  1. We connect to a local GlassFish server

  1.  We use the web explosed facet to deploy our application

  1. We have to choose to which domain deploy our application (e.g. domain1)

  1. We can start the server. The application is deployed.


WebApp built by Marco using Java 21 - Hosted in Switzerland