Create a project by Maven

sponsored links
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,:
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Create a project by Maven

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • spring struts2.0 hibernate bug killer 1

    exception There is no Action mapped for namespace / and action name checkLogin. - [Unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare ( 186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries