Build a better Web application with Google Sitebricks

Source: Internet
Author: User
Tags java web

Create a sample Java Web application using Maven, Sitebricks, and Guice

Brief introduction

Sitebricks is still in the beta phase and is a new Java™web application framework. You might want to ask, "Why do I need another WEB framework?" "With Google sitebricks, you can quickly build a WEB application that can be maintained or manipulated by others." Sitebricks is built on top of Guice. It extends many of the Guice principles to the Web. It uses annotations as heavily as Guice to use the configuration as part of the code. To use Guice, you do not need to create or edit a large number of XML files. Sitebricks allows a relatively small amount of code to be written when creating a Web application. The code you write will be simple and straightforward. You can view the Sitebricks code and quickly understand the meaning of its expression. Sitebricks does not break type safety or performance.

This article helps you understand the characteristics of sitebricks by creating a sample Web application. A sample application called REVIEWR allows users to read and write restaurant reviews. You want to use a database to keep the data that is used in your application (though it won't take too much time). This example focuses on the part of the application that utilizes the Sitebricks feature.

Download the REVIEWR Application sample code from the table at the end of this article.

Prerequisite

Sitebricks is still in beta, and this article uses version 0.8.

Currently, the easiest way to use sitebricks is to use it with Maven. This article is using the Maven 2.0.9. Of course, Maven introduces all the other dependencies sitebricks needs, such as Google Guice.

Sitebricks relies on some of the advanced features in Java, so JDK 1.6 is required. This article is using JDK 1.6.0_17.

You can use a Java Web application server to deploy the sample application in this article, but this is not a necessary step.
In addition, the sample application contains an embedded Jetty server that can be used as a test.

The Guice used by sitebricks in the sample application. It can be useful to familiarize yourself with other dependency injection frameworks such as Guice or Spring.

Using Maven to create an sitebricks application

Like many modern Java frameworks, Sitebricks uses Maven. Many frameworks use Maven's prototype system to build new projects. This is also a sitebricks plan, but Maven is not available at the time of this writing. More manual methods are used in the examples in this article. You will follow Maven best practices by first creating a business logic project, as shown in Listing 1.

Listing 1. Use Maven to create a business logic project

$ mvn archetype:create -DgroupId=org.developerworks.reviewr -DartifactId=reviewrMain
[INFO] Scanning for projects...

This code creates a simple project structure, a typical feature of a Java application that will eventually be packaged into a JAR file. The next step is to create a second project, the Web application shown below.

Listing 2. Using Maven to create a Java Web application

$ mvn archetype:create -DgroupId=org.developerworks.reviewr -
DartifactId=reviewrWeb -DarchetypeArtifactId=maven-archetype-webapp
[INFO] Scanning for projects...

This is similar to Listing 1, but this time it provides a prototype ID for Maven-archetype-webapp. It is a core prototype of Maven, and you can create a basic Java WEB application project. After you create the project, open the Pom file to add sitebricks to it. This is done first for the main business logic project, as shown in Listing 3.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.