Create an application with Spring Roo and deploy it on Google App Engine

Spring Roo is a rapid application development tool that helps you quickly build spring-based enterprise applications using the java programming language. Google App Engine is a cloud computing technology that lets you run your applications on Google's infrastructure. Using Spring Roo, you can develop applications that can be deployed on Google App Engine. In this tutorial, we will develop a simple application that can run on Google App Engine.

Roo configures and manages your applications using the Roo shell. The Roo shell can be launched as a standalone command line tool or as a view pane in the Springsource tool suite ide.

Create it quickly and efficiently
 Most people who create applications want to make them faster and more efficient. This means that if they can figure out a way to create something that both serves users and gives them the transaction speed they need, it's entirely possible that this is exactly what they need to do to get the best results. 

Most people see Google Search as a great way to get their app out into the world, and it seems like a great place to start. Launching an app that helps ordinary people get the help they need for a variety of projects means partnering with the world's most popular search engine to make it happen. Therefore, you should look at developing applications for Google to get the results you need.

Prerequisites
Before we can start using Roo shell, we need to download and install all the prerequisites.

Download and install SpringSource tool suite 2.3.3. square meters. Spring Roo 1.1.0.m2 is bundled with STS. When installing STS, the installer will ask where STS should be installed. Inside that directory, it will create a folder called "roo-%release_number%", which will contain the roo content. Add %spring_roo%/roo-1.1.0.m2/bin to your path so you can trigger the roo command from the command line.

Start STS and go to the dashboard (help->dashboard)

Click on the Extensions tab

Install "google plugin for eclipse" and "datanucleus plugin".

Restart STS when prompted.

With all the above installed, we can start building the application.

Conferenceregistration.roo app
Conference Registration is a simple app where speakers can register themselves and create the conference they want to talk about. So we'll have two entities: Speaker and Presentation. Follow the instructions to create the application:

Open the operating system command line shell

Create a directory called Meeting Registration

Change to the meeting registration directory in the command line shell

Fire Roo command. You will see a roo shell as shown below. Prompt commands give you the next action you can take to manage your application.
Type the prompt command and press Enter. Roo will tell you that first you need to create a project, and to create a project you should type "project" and hit Tab. The prompt command is very useful because you don't have to cram all the commands; it will always give you the next logical step you can take at that point.
The Roo prompt command tells us that we must create the project, so type the project command as shown below

project --toplevelpackage com.shekhar.conference.registration --java 6
This command creates a new maven project with the top-level package name com.shekhar.conference.registration and creates a directory for storing source code and other resource files Table of contents. In this command, we also specify that we are using Java version 6.

Once the project is created, enter the prompt command again and Roo will tell you that persistence must now be set. Type the following command
 
persistence setup --provider datanucleus --database google_app_engine --applicationid roo-gae

This command sets up everything needed for persistence. It creates persistence.xml and adds all dependencies required for persistence in pom.xml. We choose provider as DataNucleus and database as google_app_engine because we are developing our application for google app engine and it uses its own data store. Applicationid is also required when we deploy the application to Google App Engine. Now our persistence setup is complete.

8. Enter the prompt command again and Roo will tell you that entities must now be created. Therefore, we need to create the entity's speaker and presentation. To create the speaker entity we will type the following command
 
entity --class ~.domain.speaker --testautomatically

field string --fieldname fullname --notnull

field string --fieldname email --notnull --regexp ^([0-9a-za-z]([-.\w]*[0-9a-za-z])*@([0-9a-za -z][-\w]*[0-9a-za-z]\.)+[a-za-z]{2,9})$

field string --fieldname city

field date --fieldname birthdate --type java.util.date --notnull

field string --fieldname bio

The above six lines create an entity called session with various fields. Here, we have used not-null constraint, email regex validation, date field. Spring Roo on App Engine does not yet support enumerations and references, which means you cannot yet define one-to-one or one-to-many relationships between entities. These features are supported on Spring MVC applications, but Spring MVC applications cannot currently be deployed on App Engine. These issues exist in the Spring Roo Jira. They will be fixed in a future release (hopefully :)).

9. Next create the second entity for our application demo. To create a presentation entity, type the following command on the Roo shell
 
entity --class ~.domain.presentation --testautomatically

field string --fieldname title --notnull

field string --fieldname description --notnull

field string --fieldname speaker --notnull

The above four lines create a jpa entity called presentation, located in the domain subpackage, and add three fields - title, description and speaker. As you can see, the speaker is added as a string (just enter the full name). Spring Roo on google app engine still doesn't support references.

10. Now that we have created our entities, we must create the look and feel of our application, the user interface. Currently, only UIs created with GWT run on App Engine. Therefore, we will create the GWT user interface. do that type
 
gwt setup

This command will add the GWT controller and everything needed for the UI. This command may take a few minutes if you do not have these dependencies in your Maven repository.
11. Next you can use the following command to configure log4j to debug level
 
logging setup --level debug

12. Exit the Roo shell
13. If you have maven installed on your system, you can easily run your application locally by typing "mvn gwt:run" in your command line shell while you are at Create Project in the same directory as . This will start GWT development mode and you can test your application. Please note that the application will not run in google chrome browser when you run it from the development environment. So, it's better to run it in firefox.
14. To deploy your application to Google App Engine, just type
 
mvn gwt:compile gae:deploy

Guess you like

Origin blog.csdn.net/wouderw/article/details/128462713