官术网_书友最值得收藏!

Creating a NetBeans Maven JSF project

After launching NetBeans, open the File menu and select New Project from the available project types. Locate and select Maven. A list of Maven archetypes (project templates) is available. Select Web Application, as shown in the following screenshot:

Creating a NetBeans Maven JSF project

Click on Next and the following screenshot appears:

Creating a NetBeans Maven JSF project

Project Name is set to PFThemes.

Project Location is generated automatically and it does not need to be changed.

The following Maven properties are listed:

  • Artifact Id: This cannot be changed. It is the name of your project.
  • Group Id: This can be edited as required. This sets the base package for the project.
  • Version: This does not need to be changed.
  • Project: This is the last property that we will use to set the root package for all the Java classes in the project.

Now that we have set the name and location of the project, click on Next. This leads us to the Settings dialog box. This is where we set the application server and Java Enterprise Edition (EE) version that we are going to use for the project, as shown in the following screenshot:

Creating a NetBeans Maven JSF project

I chose GlassFish because it is the Java EE reference implementation. I selected GlassFish Server 4.0 because this is the current release version of GlassFish and the nightly builds are available to me.

Tip

You can use any Java EE 7 container that supports the Java EE 7 web profile that you like. The list of potential servers is long, but Tomcat (http://tomcat.apache.org/), TomEE (http://tomee.apache.org/), and WildFly (http://wildfly.org/) are suitable ones. Tomcat and TomEE are freely available from the Apache Software Foundation (http://apache.org/)and WildFly is available from RedHat.

Once we have set the project settings, we can finish creating it. NetBeans presents us with a Project view containing our newly created project. If it hasn't opened a Project view, open the Windows menu and select Projects. You can also open a Files and a Services view. This allows us to check the files as they are built into the project, and through the Services view we can control things such as the GlassFish server, as well as other services such as database connections.

Now that we have successfully created the project, we have to change the project properties so that it adds the JSF framework to it.

Note

The JSF framework is part of the Java EE 7 standard version. It allows developers to build views/pages that are separate from the business logic and data models that make up the middle tier of data-driven applications. Because PrimeFaces builds on the facilities provided by JSF, we need to add it to our project.

Select the project and right-click on it. This opens a context menu, which allows us to perform different tasks and control various aspects of the project itself. We are interested in the one at the bottom, Properties. We click on it to open the Project Properties dialog box and select the Frameworks option, as shown in the following screenshot:

Creating a NetBeans Maven JSF project

By clicking on the Add… button to the right, we can select a framework from a number of choices. We want JSF, so we select it and click on OK, as follows:

Creating a NetBeans Maven JSF project

We return to the Project Properties | Frameworks dialog box, which looks like this:

Creating a NetBeans Maven JSF project

The three tabs, Libraries, Configuration, and Components, are used to display and/or change the configuration of the JSF framework for our project. Libraries cannot be altered, but it shows that we are using Java EE 7 JSF version 2.2. I also changed the configuration as follows:

Creating a NetBeans Maven JSF project

The JSF Servlet URL Pattern field has been changed to *.xhtml from the default one because it makes the linking of JSF pages easier. However, this is a purely personal preference and it is not something that you need to do.

Tip

The Components tab does allow us to add the PrimeFaces library to our project. However, it adds the version bundled with NetBeans, and not the one that we will be using for our project, which is PrimeFaces 5.2 at the time of writing this book.

Once you have set up the JSF framework to your satisfaction, click on OK, and the changes will be applied to our project.

Tip

While we have been doing this, NetBeans should have been building the project in the background, including the creation of the project from its Maven archetype. Maven downloads quite a large number of files when a project is created. Luckily for us, it only does this once. Maven also maintains a local repository of resources on our workstation for us so that once a file is downloaded from the Maven Central Repository it doesn't need to be download from there again.

主站蜘蛛池模板: 思南县| 宣威市| 邮箱| 宜章县| 楚雄市| 咸宁市| 长治市| 安宁市| 靖西县| 焦作市| 郯城县| 台江县| 拉萨市| 文化| 新安县| 雅安市| 宁化县| 江华| 松潘县| 穆棱市| 洛扎县| 玉环县| 海口市| 吴旗县| 克拉玛依市| 安乡县| 自治县| 遵义县| 嘉善县| 廊坊市| 泗洪县| 定南县| 辰溪县| 玉林市| 田东县| 鄢陵县| 竹溪县| 乐山市| 大埔区| 伊吾县| 西昌市|