JavaEE7 project set up with Eclipse, Wildfly, MySql, JPA, Hibernate, EJB, CDI, JSF and RS
In this project structure we are going to create a project structure for our Application. The over all structure is going to be of three main modules and inside them will be sub modules. This is a simplest form of structure however if we need something later on in series we will include it later in the series as required.First step is to create and "Enterprise Application Project". for that right click in the project window and select project. Or you can use small project icon on the upper left corner of Eclipse window. In the project selection wizard search and select Enterprise Application Project.

In the project creation wizard enter the Project name and select target runtime, in our case Wildfly 8. If you want to configure the EAR version you can do here other wise its good enough to leave it like that and click Next.

In this part we don't have any dependencies yet so we will leave that part alone and click the checkbox displaying "Generate application.xml deployment descriptor". Afterward press click Finish to complete the wizard.
Now that EAR part is complete, this will act as a whole of container for the sub modules of our application, which are coming up in following content.
Next Create an EJB Project in the same way you created the EAR project.



We are not done yet, we will come back to this module but before there is another part to be created. In the next section we will create the Web client part for the application. In our specification we are going to do this using Web application with JSF.



We have all three component of our project ready now we need some configuration part, As you may ask, There were mention of JSF, RS, JPA, Hibernate and CDI and I haven't seen any traces of these.
Wait ! we are coming onto these now. First things first, right click the EJB project in your project explorer and go to Properties > Project Facets.


It may happen that JPA option is not yet available in the sidebar. Nothing to worry, press OK, that will save the progress and again right click the project and go to Properties. This time JPA will be enabled.

Finally click OK to complete the configuration and Exit.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head></h:head>
<h:body>
Hello World!
</h:body>
</html>
When you add the JSF facet to the project a JSF configuration file is created in WEB-INF by the name of faces-config.xml, make sure this file is there. And an entry is marked in your web.xml file under servlet tag. Just make sure initially it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>DemoWeb</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Our key concern is to make sure that URL-pattern looks like "/*" instead of "/faces/*" because in other case you would need to place the xhtml files inside faces directory.We are all set now, right click the EAR project and Run As > Run on server. the result will print Hello World on the welcome page.

No comments:
Post a Comment