Create a project by Maven

Create a project by Maven

Why do we have mentioned earlier the use Maven, Maven installation, and IDE integration, build Nexus local warehouses, which are created in our project before the formal preparations. From the beginning of this chapter we introduce the use Maven to create, manage our projects.

It is assumed that you have read my previous articles, or you have installed Maven, configured IDE integration environment. Project to create roughly divided into two, one is through the Maven's command line operation, and the other environment through the IDE interface to create, we were to introduce the following:

Through the Maven command line to create a project
Maven project created by a plug-archetype (prototype) to create, it was also translated into the frame, you can be understood as Template. Through the archetype can choose to create the basic project model, can also be preset templates to create projects, archetype pre- Purchase a lot of project templates, project templates such as Spring, EJB project templates. Now we are to introduce:

1. To create the basic project if we are to build a name for the ftpserver program on the command line prompt, execute the following command:

mvn archetype: create-DarchetypeGroupId = org.apache.maven.archetypes-DgroupId =
-DartifactId = ftpserver

The first parameter-DarchetypeGroupId is to develop plug-archetype groupId belongs

The second parameter-DgroupId is to develop your project will be created groupId, according to their own situation, and so the appropriate changes to the project

The third parameter-DartifactId is to develop the components you want to create the ID, this example is the ftpserver

After the implementation of a similar display as follows:

Here we look at the documents generated POM.xml:

<Project xmlns = " "
xmlns: xsi = " "

xsi: schemaLocation = " ">

<modelVersion> 4.0.0 </ modelVersion>

<groupId> </ groupId>

<artifactId> ftpserver </ artifactId>

<packaging> jar </ packaging>

<version> 1.0-SNAPSHOT </ version>

<name> ftpserver </ name>

<url> </ url>



<groupId> junit </ groupId>

<artifactId> junit </ artifactId>

<version> 3.8.1 </ version>

<scope> test </ scope>

</ Dependency>

</ Dependencies>

</ Project>

Here are some of the major labels next role:

• modelVersion POM files used to develop a template version, although the POM file version is not frequently updated, but compulsory for version can keep the consistency and stability of the entire project.
• groupId this tag is used to specify the item belongs to the company or organization, in this case, groupId is, that this component is based on modules are alibaba. This property is usually identified with artifaceId together a component • artifactId specify the component name, which in this case is the ftpserver, in the final document generated, where the artifactId as part of the file name appears, the standard file name format <artifactId> - <version>. <extension>, this example is ftpserver-1.0.jar
• packaging is used to specify the package type, such as JAR, WAR, EAR, etc., then the default if you do not specify the JAR, where not only can specify the packaging type, you can also specify a particular life cycle as part of the build process, on this section we will discuss in more detail.
• version to develop the project version, where more than a SNAPSHOT version of the concept, scope development process, will detail later how to use SNAPSHOT to carry out collaborative development.
• name the name of the development project, Maven generated documentation at the time the project will use the label attribute • url address of the designated site of this project, Maven generated documentation at the time the project will use the label attribute • description project descriptions, Maven generated documentation at the time the project will use the label attribute

Here we look at the generated project directory tree:


| - Pom.xml

`- Src

| - Main

| `- Java

| `- Com

| `- Alibaba

| `- Ftpserver

| `-

`- Test

`- Java

`- Com

`- Alibaba

`- Ftpserver


1. Create a template project
Above, we have created a basic project, and now we introduce how to create a template project, such as we have to create a spring project, just above steps are not enough, then the Maven template for such a project configuration you do a lot of things , let us see how to do the following, very simple to create changed to generate as long as you can, and still create a project called ftpserver the spring:

mvn archetype: generate
-DarchetypeGroupId = org.apache.maven.archetypes-DgroupId =
-DartifactId = ftpserver

Enter after the command line we can see the following prompt:

... ...

Choose archetype:

1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web applicati

on with Hibernate, Spring and JSF)

2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web applic

ation with Hibernate, Spring and Spring MVC)

3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web applic

ation with Hibernate, Spring and Struts 2)

4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web appl

ication with Hibernate, Spring and Tapestry 4)

5: internal -> appfuse-core (AppFuse archetype for creating a jar application wi

th Hibernate and Spring and XFire)

6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular app

lication with Hibernate, Spring and JSF)

7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular

application with Hibernate, Spring and Spring MVC)

8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular

application with Hibernate, Spring and Struts 2)

9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modula

r application with Hibernate, Spring and Tapestry 4)

10: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)

11: internal -> maven-archetype-marmalade-mojo (A Maven plugin development proje

ct using marmalade)

12: internal -> maven-archetype-mojo (A Maven Java plugin development project)

13: internal -> maven-archetype-portlet (A simple portlet application)

14: internal -> maven-archetype-profiles ()

15: internal -> maven-archetype-quickstart ()

16: internal -> maven-archetype-site-simple (A simple site generation project)

17: internal -> maven-archetype-site (A more complex site project)

18: internal -> maven-archetype-webapp (A simple Java web application)

19: internal -> jini-service-archetype (Archetype for Jini service project creat


20: internal -> softeu-archetype-seam (JSF + Facelets + Seam Archetype)

21: internal -> softeu-archetype-seam-simple (JSF + Facelets + Seam (no persistence)


22: internal -> softeu-archetype-jsf (JSF + Facelets Archetype)

23: internal -> jpa-maven-archetype (JPA application)

24: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)

25: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archety


26: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype)

27: internal -> maven-archetype-har (Hibernate Archive)

28: internal -> maven-archetype-sar (JBoss Service Archive)

29: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)

30: internal -> scala-archetype-simple (A simple scala project)

31: internal -> lift-archetype-blank (A blank / empty liftweb project)

32: internal -> lift-archetype-basic (The basic (liftweb) project)

33: internal -> cocoon-22-archetype-block-plain ([

aven-plugins /])

34: internal -> cocoon-22-archetype-block ([

lugins /])

35: internal -> cocoon-22-archetype-webapp ([

plugins /])

36: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces)

37: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using

MyFaces and facelets)

38: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and


39: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create c

ustom JSF components using MyFaces)

40: internal -> gmaven-archetype-basic (Groovy basic archetype)

41: internal -> gmaven-archetype-mojo (Groovy mojo archetype)

Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23 / 2

4/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15::

We can see that many of the predefined templates project, where we want to create a spring project, select 2 and then Enter, the following tips:

[INFO] artifact org.appfuse.archetypes: appfuse-basic-spring: checking for update

s from nexus

[INFO] artifact org.appfuse.archetypes: appfuse-basic-spring: checking for update

s from central

Define value for version: 1.0-SNAPSHOT::

Careful reader may notice from the nexus of local Maven repository for plugin updates, the premise is to build up their local warehouse, before the articles we have talked about how to create a nexus of local storage. Bold part is said to prompt Your project's initial version, it gives a default value of 1.0-SNAPSHOT, usually without special needs, we can confirm you can Enter the default rules, you can also enter a custom version, but are not recommended such a do. Enter will see the following prompt:

Define value for version: 1.0-SNAPSHOT::

Confirm properties configuration:


artifactId: ftpserver

version: 1.0-SNAPSHOT



Maven will give you information about the project to confirm the absence of errors, you can directly press Enter, and then you can see the efforts of Shuabing Maven to build a spring project for you, if you can see in the final similar information, it means the project has been created successfully:

[INFO] OldArchetype created in dir: D: \ work \ projects \ test \ ftpserver

[INFO] ----------------------------------------------- -------------------------


[INFO] ----------------------------------------------- -------------------------

[INFO] Total time: 69 minutes 48 seconds

[INFO] Finished at: Fri Jun 26 11:45:52 CST 2009

[INFO] Final Memory: 9M/127M

[INFO] ----------------------------------------------- -------------------------

Bold part of the prompt success of the project construction.

Then we take a look at POM file this any different from the last, Maven generates a POM file around line 700, which almost includes a project should have everything, build, automatic unit testing, component dependencies, Statements (site), database connection, SCM, etc., we can choose according to actual needs we need to project cycle management, as the code is not posted too much out here. in the POM file Xiangjie back inside, I will introduce some commonly used tags POM file and how to use.

Here let's look at the directory structure What is the difference:


| - Pom.xml

`- Src

| - Main

| `- Java

| `- Com

| `- Alibaba

| `- Ftpserver

| `-

| - Resources

| - Webapp

| - Site

`- Test

| `- Java

| `- Com

| `- Alibaba

| `- Ftpserver

| `-

| - Resources

We can see the bold part of the site is more than Maven generated site for the project, all the reports will be generated at this site which, in the resources directory there will be a lot of resource files, such as multi-language resource files. This is According to rules established by the default project directory structure, of course, you can customize the directory structure, but we recommend to use in future projects maven's default rules.

On the Maven life cycle management, we will discuss in later chapters.

Through the IDE (IDEA) to create a project through the command line if you create the project, to IDE (eclipse, or Intellij IDEA) to develop, only a simple command to generate eclipse or IDEA project file:

mvn idea: idea

mvn eclipse: eclipse

Only need to run after the corresponding project file in the IDE which you can follow up the development work.

If you do not like using the command line, then you also can In the IDE which graphically oriented interfaces to create Project, the IDEA Neibujicheng of the Maven support, if using the eclipse of the Hua you need to download m2e plug-in. Here Women with IDEA Wei cases to create a project before the case:

1.File-> new project, then select the first Create project from scratch, click Next to see:
The lower left corner choose Maven Module, complete catalog information, click Next

1. Here is a check box, Create from archetype, if not the election is to create a basic item, tick in the box above, then you can choose the type of project you want to create, where we choose to follow that example as before type: appfuse-basic-spring, click Finish to complete the project creation.
2. Through the command line and IDE generated project POM file and directory structure is the same:

Summary Through this chapter, we learned how to create a Maven project according to our needs, command line mode and IDE mode, not by way of command line operating system constraints, there is no interface in the operating system Linux and other life-cycle management , this late in the project, we need the command line method in the test server, pre-release Fuwu Qi and Shengchanhuanjing Fu Wuqi Jinhangxiangying life cycle management. IDE mode for the early establishment of the project and development process, can easily interface the way through to manage the project life cycle. The following chapter, I will detail Maven POM file, and the life cycle.

This article comes from CSDN blog,:

分类:Development 时间:2010-09-01 人气:368
blog comments powered by Disqus


  • Interface prototype in software application development 2010-03-01

    Prototyping in the software development process is now widely used. First of all, we must be clear that any method or tool is Wei we develop, produce process service of, this must be clearly we can not become the slave method or tool, as long as we t

  • The meaning of the interface prototype 2010-10-16

    Recently a prototype written in accordance with the interface implementation code, the process of doing some of the problems encountered, such as a drop-down list select a city, simply lists the name of several cities, and there is no real definition

  • On the interface prototype design 2011-04-27

    I do not know what tools are made with the prototype interface White paper, pencils, erasers, and sometimes also need scissors. Unfortunately, in most cases is not high fidelity process and difficult to express the page; Word. . . . PPT. . . Flash, w

  • [Top] Maven to deploy multi-module Maven project eclipse hot-hot-deploy tomcat project implementation. 2011-09-03

    Maven multi-module project in eclipse, the following hot deployment, which you can experience the entire project under the inside whether you modify the code of any module, no need to use maven package you can see the effect, 1, the first ready to cr

  • android project reported that your project contains error (s) exception, not the implementation 2011-01-03

    Android using Eclipse to write procedures, often following exceptions: your project contains error (s), please fix them before running your application The solution: 1, eclipse restart, if not the implementation of the second step. 2, the first item

  • The significance of the prototype interface 2010-10-16

    Recently prepared in accordance with the prototype interface implementation code, the process of doing some of the problems encountered, such as a drop-down list, select a city, but simply lists the name of several cities, and there is no real defini

  • Used in the maven 3 implementation lifecycle participant in profiles.xml maven 2 2010-10-23

    The Compatibility Notes in the maven 3 mentioned maven 3 no longer supports the pom or settings outside the profile, instead proposed to put these settings in the profile. We always wanted a tool that is dependent on the maven 2 in the independent pr

  • Apache Servicemix learning (2) ------ The first project 2010-08-15

    Create a project using maven. 1. Project directory path: / opt / ericWorkspace / servicemix 2. Servicemix create a pom.xml file directory contents: <?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apach

  • Securing Web Applications with Apache Shiro(1) 2014-02-10

    Table of Contents Overview While Apache Shiro's core design goals allow it to be used to secure any JVM-based application, such as command line applications, server daemons, web apps, etc, this guide will focus on the most common use case: securing a

  • Apache open source project classification list 2009-10-13

    Original link: Apache open source project classification list Categories Project name Description The development of language Server (20) Apache HTTP Server HTTP server first in the world C / C +

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.121 (s). 12 q(s)