Creating the Java EE Server Application

Creating the Java EE Server Application

Java EE is a community-driven specification-based platform that provides facilities and techniques for creating enterprise applications on the Java platform, primarily for deployment to the browser. In this section, you will create a Java EE application that makes use of Java EE specifications that relate to database access and data exposure via web services.

Let’s begin by setting up a new Java EE application. The de-facto standard build system for Java applications is Maven , which is conveniently supported in the IDE, as you will see while working through the following steps.

1. To get started creating the application, go the New Project window, which you can do via File ➤ New Project or by clicking Ctrl+Shift+N. In the New Project window,

choose Maven ➤ Web Application, as shown in Figure 5-3 .

Figure 5-3. Getting started creating a Maven-based Java EE application

2. When you click Next, the “Name and Location” step of the wizard, shown in Figure 5-4 , enables you to fill in Maven-specific settings. Aside from the name of the project and its location, you’re prompted to specify the group ID, version, and optionally a package name, which will be treated as the main package of the application that will be created.

Figure 5-4. Maven settings for Maven-based Java EE application

■ Note The Maven group ID is an organizational setting; typically you would take the URL of your website and reverse it, so that if your site is mycompany.com , the group ID, as well as the package setting, would start off

with com.mycompany . This creates a unique identifier or namespace for your application’s base structure.

3. After clicking Next, select the application server to which the application will be deployed, as well as the Java EE version to which its artifacts and structure will comply; see Figure 5-5 . Wizards and templates in the IDE will generate code conforming to the selected Java EE version. Here, choose GlassFish and Java EE.

Figure 5-5. Server name and Java EE settings for Maven-based Java EE application

When you click Finish, the application structure with its initial content is created and shown in the Projects window of the IDE, as shown in Figure 5-6 .

Figure 5-6. Newly created Maven-based Java EE application Take a moment to explore the Maven-related facilities that the IDE makes available. For example, when

you open the POM ( pom.xml) file, you will notice multiple tabs, including a graph view. When you open the Navigator (Ctrl+7), you will notice a list of Maven goals, defined in the POM, which you can right-click to execute. When you go to the Action tab in the Project Properties window of the project, you can bind Maven goals to project commands, such as Build and Run, which you can invoke via keyboard shortcuts.

Now that you have created the structure and initial content of your Java EE backend, you’re ready to generate into it your JPA entity classes from the Sample database, which you set up earlier in this chapter.