`
郭亲华
  • 浏览: 48180 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

maven

    博客分类:
  • J2EE
阅读更多
1、构建单个工程
Maven2在项目管理方面影响越来越大,很多项目都使用Maven2。下面我们就介绍如何使用Maven2快速创建项目原型,然后在此基础上进行项目开发。下面我们就看一下如何使用Maven2创建典型的三类项目:
普通的Java项目,如基础包等:
   mvn archetype:create   -DgroupId=com.yourcompany  -DartifactId=myproject  -DarchetypeArtifactId=maven-archetype-quickstart
普通的Web项目,如一个Web项目:
    mvn archetype:create  -DgroupId=com.yourcompany -DartifactId=myproject  -DarchetypeArtifactId=maven-archetype-webapp
Appfuse中的Struts 2.0项目:
    mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m4-SNAPSHOT -DgroupId=com.mycompany -DartifactId=myproject
使用上述命令后,你可以很快捷地生成你想要的项目原型。接下来我们只需使用下面命令,生成IDEA的项目文件,然后打开就可以在IDEA下进行项目开发啦。
     mvn idea:idea -DdownloadSources=true -DdownloadJavadocs=true -DjdkLevel=1.5
当pom.xml文件发生变化时,我们只需使用下面命令重新生成module文件即可,新生成的module文件会和原来module文件进行很好的合并,通常是依赖的package发生变化啦。
    mvn idea:module

2、构建Maven父子工程
1. 先单独构建各模块为一个独立的项目。
jar项目:
Dos代码
mvn archetype:create -DgroupId=org.sonatype.mavenbook.weather -DartifactId=simple-weather 

war项目:
Dos代码
mvn archetype:create -DgroupId=org.sonatype.mavenbook.web -DartifactId=simple-webapp  
-DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId=maven-archetype-webapp 

2. 构建父项目,并将各子模块文件拷贝到父项目路径下。
Dos代码
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch06 -DartifactId=simple-parent  
-DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId=maven-archetype-webapp 

3. 修改父项目pom.xml与各子模块pom.xml配置对应关系。
父项目的pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom </packaging>
<version>1.0</version>
<name>simple-parent Maven Webapp</name>
<url>http://maven.apache.org</url>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules >

子项目的pom.xml
<parent>
        <groupId>com.your-company.xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0</version>
        <relativePath>../pom.xml</relativePath>
</parent>
4. 在父项目路径下执行:mvn eclipse:m2eclipse
5.在配有m2eclipse 插件的eclipse中导入父项目路径下的项目,导入为m2eclipse project。

------------------------------------------------------------------------------------------------------------------
mvn archetype:create -DgroupId=org.cjj.site -DartifactId=org.cjj.site -DpackageName=org.cjj.site -DarchetypeArtifactId=maven-archetype-webapp
重要的
Script代码
archetypeArtifactId
不是吗?
但是,当我们创建spring项目或者struts项目,到哪里去查他们的archetypeArtifactId呢?
我google了一下,发现一个好资源:http://cwiki.apache.org/confluence/display/WW/Struts+2+Maven+Archetypes
呵呵,今天发现原来可以这样:
Script代码
mvn archetype:generate
接下来的事情,很舒服,选择一个类别吧.
Java代码
E:\workspace>mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]  task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application 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 modular 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 project 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 creation)
20: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
21: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype)
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 archetype)
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 ([http://cocoon.apache.org/2.2/maven-plugins/])
34: internal -> cocoon-22-archetype-block ([http://cocoon.apache.org/2.2/maven-plugins/])
35: internal -> cocoon-22-archetype-webapp ([http://cocoon.apache.org/2.2/maven-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 Trinidad)
39: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create custom 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/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41) 15: :
选择41个类型,有你所要的吗?选择一个数字即可.
下面就剩下你根据提示来填空了.
分享到:
评论

相关推荐

    maven安装maven安装maven安装maven安装maven安装

    maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装maven安装...

    Maven全版本资源,Maven 3.0.5-3.8.5,每个版本包含4个文件,Maven3全资源打包下载,Maven全集

    apache-maven-3.0.5 apache-maven-3.1.1 apache-maven-3.2.5 apache-maven-3.3.9 apache-maven-3.5.4 apache-maven-3.6.3 apache-maven-3.8.5 每个版本包含4个文件: apache-maven-3.8.5-bin.tar.gz apache-maven-...

    开源工具Maven3.9.4版本压缩包

    Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven3.9.4版本压缩包,仅供学习参考,更新版本请前往Maven官方下载;Maven...

    maven 3.8.8 解压安装版

    Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。 Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,...

    maven3.2.5安装包下载

    Maven最新版是款项目管理和构建自动化工具。Maven包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个依赖管理系统(Dependency Management System)。 安装...

    apache-maven-3.8.5

    Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。 Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,...

    apache-maven-3.8.6.zip

    apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-maven-3.8.6-bin.zip apache-...

    maven历史版本下载

    maven

    maven_repository .zip

    Maven框架,本地jar资源仓,中央仓下载jar资源 有时在你的构建过程中,需要将第三方jar包添加到本地仓库中,因为它并存在于像Maven中央仓库或其它的公共仓库中。为了让Maven能够正确获取到jar包,第三方jar包必须...

    apache-maven-3.6.zip

    Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache ...

    apache-maven-3.3.3.zip

    maven

    maven离线安装插件

    4、在links中新建maven.txt文件,内容为插件地址,例如:path=D:\eclipse_gzds\myplugins\maven(注意这里斜杠,不是反斜杠) 5、将maven.txt扩展名改为maven.lin 6、在eclipse根目录下找到eclipse.ini并打开,在...

    apache-maven-3.5.0

    maven-3.5.0版本的本地资源包,直接解压就可使用。 方式1 需要在系统环境变量中直接配置path中配置,路径是到bin目录。 方式2 新建配置(MAVEN_HOME),路径为是解压后的maven根目录,再在path中引用(%MAVEN_HOME%\...

    apache-maven-3.8.6-bin.tar.tz--test

    apache-maven-3.8.6-bin.tar.tz--test apache-maven-3.8.6-bin.tar.tz--test apache-maven-3.8.6-bin.tar.tz--test apache-maven-3.8.6-bin.tar.tz--test apache-maven-3.8.6-bin.tar.tz--test apache-maven-3.8.6-...

    Maven权威指南中文版.pdf

    Maven是一种构建工具,一种项目管理工具,一种用来运行构建任务的抽象容器。对于那些成熟的,希望用一致的方式来管理和构建大量相互依赖的模块和类库,并且使用了 数千第三方组件的项目来说,Maven已经证明了它是一...

    apache-maven-3.2.5-src.zip

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。 Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用...

    apache-maven-3.8.6-bin+安装教程

    maven本地仓库的默认位置:无论是Windows还是Linux,在用户的目录下都有一个.m2/repository/的仓库目录,这就是Maven仓库的默认位置,变更maven默认的本地仓库的位置可更改存在于maven的settings.xml文件中local...

    eclipse maven3 plugin.zip

    直接离线安装eclipse中的maven插件,在你的eclipse安装根目录下创建两个文件夹:links,myplugins(文件夹名字可以自定义),所在路径D:\eclipse。将下载下来的maven插件放到myplugins下。载links目录下创建一个...

    下载慢?给你apache maven 3.x.x所有Linux, Windows版本下载的百度网盘链接

    apache maven 3.x.x所有Linux, Windows版本下载的百度网盘链接。 apache-maven-3.0.4-bin.tar.gz apache-maven-3.0.4-bin.zip apache-maven-3.0.5-bin.tar.gz apache-maven-3.0.5-bin.zip apache-maven-3.1.0-bin....

    maven的本地仓库配置文件settings.xml和项目中文件pom.xml.zip

    一、Idea关联的maven本地仓库配置文件settings.xml (1)必须使用默认文件名 D:\developsoft\javaweb\commonPlugins\maven\apache-maven-3.8.1_first\conf\settings.xml 二、Myeclipse关联的maven本地仓库配置文件...

Global site tag (gtag.js) - Google Analytics