Java EE Web Profile (EJB) quickstart tutorial with Maven, Intellij and Glassfish
source link: https://marco.dev/2012/09/30/java-ee-web-profile-ejb-quickstart-tutorial-with-maven-intellij-and-glassfish/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
java-version.com: What's new in Java 16? 15? Keep up to date!
Java EE Web Profile (EJB) quickstart tutorial with Maven, Intellij and Glassfish
This short tutorial has the goal to show how to start as fast as possible a new EJB project using IntelliJ and Maven.
- Create a new project from scratch
- Complete the form, you have to choose the Maven module
- Complete the Maven information
- Your project is created according to Maven standards
- 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.
- Create a new Class, this class is of type Stateless (a Service for who comes from Spring)
- 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.
- We create our web configuration. Add a web.xml file under WEB-INF
- The web.xml file is quite traditional, you can use one of the many templates on the web
- We can create now the managed bean, it’s the controller who manage the communication between the View (jsp) and the Model (EJB)
- 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.
- We can now create facelets page
- We call the view Hello.xhtml and we place it in the main webapp folder
- 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.
- We connect to a local GlassFish server
- We use the web explosed facet to deploy our application
- We have to choose to which domain deploy our application (e.g. domain1)
- We can start the server. The application is deployed.
Author
Marco Molteni
Marco Molteni Blog
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK