Java EE support has been included with Apache NetBeans since release 11.0. Prior to this release, Java EE support had to be added to Apache NetBeans 9.0+ as a plugin, since it was still licensed under Oracle. If the plugin was added, the functionality for developing, debugging, and maintaining Java EE was the same in Apache NetBeans 9.0 as it is in release 11.0 and beyond. The support provides the ability to add application server containers that can be managed from within the IDE. Full support for Maven web applications and Java EE technologies such as Enterprise JavaBeans (EJB), Contexts and Dependency Injection (CDI), and JavaServer Faces (JSF) allows developers the convenience of auto-completion, code fragments, and easy syntax recognition. The bottom line is that Apache NetBeans is a tremendous tool for development of Java EE applications … both older and modern.
In this chapter, we’ll take a look at the support, in detail, that Apache NetBeans provides for Java Enterprise development. You will learn how to manage containers from within the IDE, develop back-end business logic, and Java Persistence API (JPA) queries. In the end, you will have a basic understanding of the conveniences provided by Apache NetBeans for full stack Java EE development.
Configuring Server Containers
Before you can associate application projects with a container for deployment or testing, you must register one or more application server containers for use by Apache NetBeans. It is a good idea to register a container with Apache NetBeans even in the case where you are developing microservices that will be deployed to a container, such as Payara Micro or Wildfly. Note that it is good practice to only configure application server containers for development purposes within Apache NetBeans, and not for deployment to production containers.
- 1.
Navigate to the Services window and right-click on the Servers menu selection. Click Add Server, as shown in Figure 5-1.
- 2.
When the Add Server Instance dialog appears, choose the server type that you wish to add (Figure 5-2).
- 3.
On the next screen, enter the path to the application server installation that you would like to configure within Apache NetBeans (Figure 5-3). Once you have chosen the location, click the Finish button.
- 4.
It is now possible to deploy applications to the application server container(s) that have been registered within the IDE. To do so, right-click on an enterprise application project (Maven Web Application, etc.) and then specify the server of choice within the project properties. Note that you can also perform some basic application server tasks by selecting the application server from within the Servers window (Figure 5-4).
Creating a Maven Web Application
There are a variety of configurations from which to choose for the creation of Java Enterprise projects within Apache NetBeans. This chapter covers the creation of Maven Web Applications in detail, which is the de facto standard and default project selection for Java EE and Jakarta EE development within Apache NetBeans.
Note
The Java with Maven category allows the creation of projects using the old-style Java EE and J2EE configurations such as EJB Module and Enterprise Application. In most cases, these projects are no longer being used for creating new applications. However, they remain supported by Apache NetBeans.
Developing JSF Applications
Utilizing the Apache NetBeans IDE, it is easy to develop JSF applications due to the wizards and file recognition. In this section, we will walk through the development of a JSF application from a standard Maven Web Application project. Therefore, if you haven’t done so already, utilize the information in the previous section to create a bare-bones project.
Creating JSF Application Files
JSF Page
JSF Managed Bean (This creates a CDI Controller when using Java EE 7+)
JSF Faces Configuration
JSF Composite Component
JSF Resource Library Contract
JSF Pages from Entity Classes
JSF Faces Component
Faces Template
Faces Template Client
Note
As of Java EE 7+ and Jakarta EE 8, you should not be creating JSF Managed Beans any longer. This is because the JSF Managed Bean technology is being deprecated in favor of CDI beans. Therefore, the JSF Managed Bean option creates a CDI Controller.
The JSF Managed Bean file selection opens a dialog that allows one to generate a CDI Managed Bean controller class (Figure 5-10). The dialog provides the ability to add the bean data to the faces-config.xml file, if desired, as well as choose the scope of the bean.
Note
The faces-config.xml (JSF Faces Configuration) file is not generated by default, as it is not a required file for a JSF project. However, it can be added using the Other..., JavaServer Faces context menu.
The JSF Faces Configuration file selection is used to generate a faces-config.xml file for a project. However, this option is not required if you choose to create a JSF project within the NetBeans Project Creation wizard.
The JSF Pages from Entity Classes file selection can be quite powerful in that it allows you to choose an Entity Class from which to generate one or more JSF pages, resulting in the page(s) being bound to the entity class for generation and update of those entity records. In order to use this option, the project must contain at least one entity class.
Developing Entity Classes
The Entity Class file type allows you to generate a blank entity class. The Entity Classes from Database file type allows you to create entity class(es) based upon the selected database tables. In doing so, all of the requisite code for mapping the entity class(es) to the selected database tables are automatically generated for you.
Using Java Persistence Query Language (JPQL)
- 1.
Right-click the persistence.xml configuration file to open the context menu.
- 2.
Click Run JPQL Query to open the tool (Figure 5-12), type the query, and click the Run button on the upper right-hand side of the query editor.
NoteTo add a persistence.xml configuration file for JPA configuration, right-click on the project and choose: Other…, Persistence, Persistence Unit.
Deploying and Debugging
The Apache NetBeans IDE makes the development life cycle for enterprise applications very easy. To deploy and test a Maven Web Application, ensure that a local application server container target that is registered within Apache NetBeans is set correctly within the “Run” tab of the project properties. Once set, a project can be deployed by right-clicking on the project and choosing “Run” from the contextual menu. Once chosen, the project WAR file is deployed to the target application server if everything is compiled correctly, and the application is opened in the default browser.
Note
A different default browser can be configured for each project within Apache NetBeans by selecting the browser in the toolbar (Figure 5-13).
To debug a project, right-click on the project and choose “Debug” from the contextual menu. This will cause the target application server container to start in “Debug” mode, and the project WAR file will be deployed accordingly. When the application server is started in debug mode, breakpoints can be set within the project and watches can also be configured, just as is the case with standard Java SE applications. Please refer to Chapter 6 for more details on debugging and profiling applications.
Other Java EE Support Features
The Apache NetBeans 11.0 IDE contains support for a number of file types to aid the development of Java EE applications. There have been a number of wizards covered previously in this chapter, and in this section, we will take a brief look at some of the file support.
By right-clicking on a project package, then choosing “New” ➤ “Other” the “New File” dialog appears. This dialog contains a number of categories, including “Web,” “HTML5/JavaScript,” “Bean Validation,” and “Contexts and Dependency Injection” to name a few. Inside each of these categories are a number of file options. Each of the supported file types includes auto-complete for the syntax, color coding, and nice formatting.
JSP
JSF
Servlet
Filter
Web Application Listener
WebSocket Endpoint
HTML
XHTML
Cascading Style Sheet
JavaScript
Json
Tag Libraries
Some of the file types will be placed into the “Web Pages” folder of a web project, while others will create Java source files or XML configuration. Each of the file types in this section are geared toward front-end development.
HTML/JavaScript
JavaServer Faces
Bean Validation
Struts
Spring Framework
Enterprise JavaBeans
Contexts and Dependency Injection
Selenium Test
Persistence
Web Services
GlassFish
WebLogic
Other
Summary
The Apache NetBeans IDE includes exceptional support for Java EE applications. It is easy to build a Java EE project from the ground up, with options for generating front-end, back-end, and configuration files. By adding a container for deployment, the IDE allows for easy debugging and deploy-on-save options. Apache NetBeans helps boost productivity for beginner and advanced enterprise developers alike.