All Downloads are FREE. Search and download functionalities are using the official Maven repository.

archetype-resources..cheatsheet.xml Maven / Gradle / Ivy

Go to download

An archetype that generates a starter Java EE 6 webapp project for JBoss EAP 6

The newest version!
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
#set($packagePath=$package.replace(".","/"))
 


  
    
This quickstart shows off all the new features of Java EE 6, and makes a great starting point for your project.


Bean Validation

Bean Validation is a new specification in Java EE 6, inspired by Hibernate Validator. It allows application developers to specify constraints once (often in their domain model), and have them applied in all layers of the application, protecting data and giving useful feedback to users.

JAX-RS: The Java API for RESTful Web Services

JAX-RS is a new specification in Java EE 6. It allows application developers to easily expose Java services as RESTful web services.
The ${artifactId} application shows off a number of Java EE technologies such as CDI, JSF, EJB, JTA, JAX-RS and Arquillian. It does this by providing a member registration database, available via JSF and JAX-RS.

As usual, let's start by looking at the necessary deployment descriptors. By now, we're very used to seeing beans.xml and faces-config.xml in WEB-INF/ (which can be found in the src/main/webapp directory of the example). Notice that, once again, we don't need a web.xml. There are two configuration files in WEB-INF/classes/META-INF (which can be found in the src/main/resources directory of the example) — persistence.xml, which sets up JPA, and import.sql which Hibernate, the JPA provider in JBoss AS 7, will use to load the initial users into the application when the application starts. We discussed both of these files in detail in The greeter example in depth, and these are largely the same.
Next, let's take a look at the JSF view the user sees. As usual, we use a template to provide the sidebar and footer. This one lives in WEB-INF/templates/default.xhtml: That leaves the main page, index.xhtml, in which we place the content unique to the main page: Next, let's take a look at the Member entity, before we look at how the application is wired together: Let's take a look at MemberRepository, which is responsible for interactions with the persistence layer: Next, let's take a look at MemberListProducer, which is responsible for building the list of members, ordered by name. It uses JPA 2 criteria to do this. Let's now look at MemberRegistration, the class that allows us to create new members from the JSF page Now, let's take a look at the Resources class, which provides resources such as the entity manager. CDI recommends using "resource producers", as we do in this example, to alias resources to CDI beans, allowing for a consistent style throughout our application: Of course, we need to allow JSF to interact with the services. The MemberController class is responsible for this: Before we wrap up our tour of the ${artifactId} example application, let's take a look at how the JAX-RS endpoints are created. Firstly, {JaxRSActivator}}, which extends Application and is annotated with @ApplicationPath, is the Java EE 6 no XML approach to activating JAX-RS. The real work goes in MemberResourceRESTService, which produces the endpoint: Right-click the project and select Run As > Run On Server or click on the "Click to Perform" link below. If you've been following along with the Test Driven Development craze of the past few years, you're probably getting a bit nervous by now, wondering how on earth you are going to test your application. Lucky for you, the Arquillian project is here to help!

Arquillian provides all the boiler plate for running your test inside Red Hat JBoss Enterprise Application Platform 6 or JBoss AS 7, allowing you to concentrate on testing your application. In order to do that, it utilizes Shrinkwrap, a fluent API for defining packaging, to create an archive to deploy. We'll go through the testcase, and how you configure Arquillian in just a moment, but first let's run the test.
Arquillian defines two modes, managed and remote. The managed mode will take care of starting and stopping the server for you, while the remote mode connects to an already running server.

The following action starts the test in the remote mode because you have started the server in the previous step.
Right-click the project, select Properties>Maven and enter arq-jbossas-remote to the Active Maven Profile field. After that, right-click the project and select Run As>JUnit test.
So far so good, the test is running. But what does the test look like? As you can see, Arquillian has lived up to the promise - the test case is focused on what to test (the @Deployment method) and how to test (the @Test method). It's also worth noting that this isn't a simplistic unit test - this is a fully fledged integration test that uses the database.

Now, let's look at how we configure Arquillian. First of all, let's take a look at arquillian.xml in src/test/resources.
Now, we need to look at how we select between containers in the pom.xml: And that's it! As you can see Arquillian delivers simple and true testing. You can concentrate on writing your test functionality, and run your tests in the same environment in which you will run your application.

Arquillian also offers other containers, allowing you to run your tests against Weld Embedded (super fast, but your enterprise services are mocked), GlassFish, and more.

More info on Arquillian you can find on the Arquillian project page.
What we didn't tell you about the Kitchensink quickstart is that it is generated from a Maven archetype. Using this archetype offers you the perfect opportunity to generate your own project.

In order to perform that, you should select Help>JBoss Central and click the Java EE Web Project wizard.
You will get a brand new project with the same functionality as ${artifactId}, but customized with your details.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy