7.2. Create a New Project from Blank Project

Caution

This version is already obsolete. Please check the latest guideline.

This chapter describes a method to create a new project from a blank project.

7.2.1. Prerequisites

This chapter presumes that the following conditions are in place. If these prerequisites are not fulfilled, first set up the same.

  • Spring Tool Suite should be operational.
  • Maven should be executable in command line.
  • Internet connectivity.

Note

If it is required to connect to the internet through proxy server, STS proxy settings and Maven proxy settings are required.


7.2.2. Verification Environment

In this chapter, operations are validated in versions given below.

Type Name
OS Windows 7
JVM Java 1.7
IDE Spring Tool Suite 3.6.3.RELEASE (hereafter called as “STS”)
Build Tool Apache Maven 3.2.5 (hereafter called as “Maven”)
Application Server Pivotal tc Server Developer Edition v3.0 (enclosed in STS)

7.2.3. Types of Blank Project

Following two types of blank projects are provided depending on usage.

Type Usage

This should be used when developing a real application that is to be released in commercial environment.

Following types of project templates are provided as Archetype of Maven.

  • Template that includes settings for MyBatis3
  • Template that includes settings for JPA (Spring Data JPA)

This guideline recommends using a project having multi-project structure.

This should be used when creating simple applications such as POC (Proof Of Concept), prototype, sample, etc.

Following types of project templates are provided as Archetype of Maven. (Projects for Eclipse WTP are also provided; however, their description is omitted in this chapter)

  • Template that includes settings for MyBatis3
  • Template that includes settings for JPA (Spring Data JPA)
  • Template that does not depend on O/R Mapper

This guideline follows a procedure wherein various tutorials are performed using a single project.


7.2.4. Create a project of multi-project structure

For method of creating a project of multi-project structure, refer to: “Create Web application development project”.

The above document includes

  • Method to create a project of multi-project structure
  • Method to create a war file
  • Description of customized locations from blank project
  • Description of project structure

7.2.5. Create a project of single-project structure

This section describes about how to create a project of single-project structure.

First, go to the folder wherein a project is to be created.

cd C:\work

Create a project using archetype:generate of Maven Archetype Plugin.

mvn archetype:generate -B^
 -DarchetypeCatalog=http://repo.terasoluna.org/nexus/content/repositories/terasoluna-gfw-releases^
 -DarchetypeGroupId=org.terasoluna.gfw.blank^
 -DarchetypeArtifactId=terasoluna-gfw-web-blank-mybatis3-archetype^
 -DarchetypeVersion=5.0.1.RELEASE^
 -DgroupId=todo^
 -DartifactId=todo^
 -Dversion=1.0.0-SNAPSHOT
Parameter Description
-B
batch mode (interaction omitted)
-DarchetypeCatalog
Specify repository of TERASOLUNA Server Framework for Java (5.x). (fixed)
-DarchetypeGroupId
Specify groupId of blank project. (fixed)
-DarchetypeArtifactId

Specify archetypeId (ID to identify template) of blank project. (customization is necessary)

Specify any of archetypeId given below.

  • terasoluna-gfw-web-blank-mybatis3-archetype
    Template that includes settings for MyBatis3
  • terasoluna-gfw-web-blank-jpa-archetype
    Template that includes settings for JPA (Spring Data JPA)
  • terasoluna-gfw-web-blank-archetype
    Template that does not depend on O/R Mapper

In above example, terasoluna-gfw-web-blank-mybatis3-archetype is specified.

-DarchetypeVersion
Specify the version of blank project. (fixed)
-DgroupId

Specify the groupId of project to be created. (customization is necessary)

In above example, "todo" is specified.

-DartifactId

Specify the artifactId of project to be created. (customization is necessary)

In above example, "todo" is specified.

-Dversion

Specify the version of project to be created. (customization is necessary)

In above example, "1.0.0-SNAPSHOT" is specified.

Warning

In pom.xml of blank project, dependency on in-memory database (H2 database) is specified. This setting is used to perform minor validations (prototype creation or POC (Proof Of Concept)). It is not assumed to be used in actual development.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

When H2 Database is not to be used, this setting should be deleted.


7.2.6. Import a project in IDE (STS)

This section describes about how to import a created project in STS.

Note

Here, an example to import a single project is given; however, multi projects can also be imported using the same procedure.


From STS menu, select [File] -> [Import] -> [Maven] -> [Existing Maven Projects] -> [Next] to open a dialog for selecting the project created using archetype.

Open the dialog to import project

Set C:\work\todo in Root Directory, and click [Finish] while pom.xml of todo is selected in Projects.

Import project

When import is successful, a project shown below is displayed in Package Explorer.

workspace

Note

If build error occurs after import, right click the project name and click “Maven” -> “Update Project…”. Then by clicking “OK”, the error may get resolved.

../_images/CreateProjectFromBlankUpdateProject.png

Tip

Display format of package is “Flat” by default; however, view is better if set to “Hierarchical”.

Click “View Menu” of Package Explorer (down arrow on the extreme right), and select “Package Presentation” -> “Hierarchical”.

../_images/CreateProjectFromBlankPresentationHierarchical.png

When Package Presentation is set to Hierarchical, the display would be as follows:

../_images/CreateProjectFromBlankPresentationHierarchicalView.png

7.2.7. Deploy and start application server (ts Server)

The section describes about how to deploy and launch a project on application server on STS.

Note

In case of multi projects, projects (archetypeId-web) storing the components of application layer (Web layer) will be deployment targets.


Right click the imported project and select “Run As” -> “Run on Server”.

../_images/CreateProjectFromBlankRunOnServer.jpg

Select AP server (Pivotal tc Server Developer Edition v3.0), and click “Next”.

../_images/CreateProjectFromBlankTcServerNext.jpg

Check whether the selected project is included in “Configured” and click “Finish” to start the server.

../_images/CreateProjectFromBlankTcServerFinish.jpg

Note

The error that occurs at the time of starting the application server may get resolved if clean operations given below are performed.

  • Clean project
    From STS menu, select [Project] -> [Clean…], select the target on Clean dialog and click “OK”.
  • Clean deployed resource
    Right click “tc Server” of “Servers” view -> [Clean…]
  • Clean work directory of application server (tc Server)
    Right click the “tc Server” of “Servers” view -> [Clean tc Server Work Directory…]

If http://localhost:8080/todo is accessed in browser, screen shown below is displayed.

../_images/CreateProjectFromBlankTopPage.png