ITPub博客

首页 > 应用开发 > Java > 创建Maven模板项目

创建Maven模板项目

原创 Java 作者:壹頁書 时间:2016-01-10 18:46:38 0 删除 编辑
假如已经存在了一个项目,
http://blog.itpub.net/29254281/viewspace-1974603/

这个项目已经搭建好了springmvc,spring和MyBatis的环境
把这个项目转为Maven模板,以后新建项目可以直接从模板生成,省去项目搭建的步骤.


查看帮助信息
E:\workspace\songod>mvn archetype:help
archetype:create-from-project
  Creates an archetype project from the current project.

  This goal reads your source and resource files, the values of its parameters,
  and properties you specify in a .property file, and uses them to create a
  Maven archetype project using the maven-archetype packaging. If you build the
  resulting project, it will create the archetype. You can then use this
  archetype to create new projects that resemble the original.

  The maven-archetype-plugin uses Velocity to expand template files, and this
  documentation talks about 'Velocity Properties', which are values substituted
  into Velocity templates. See The Velocity User's Guide for more information.

  This goal modifies the text of the files of the current project to form the
  Velocity template files that make up the archetype.

  GAV
    The GAV values for the current project are replaced by properties: groupId,
    artifactId, and version. The user chooses new values for these when
    generating a project from the archetype.
  package
    All the files under one specified Java (or cognate) package are relocated to
    a project that the user chooses when generating a project. References to the
    class name are replaced by a property reference. For example, if the current
    project's sources are in the package org.apache.saltedpeanuts, then any
    example of the string org.apache.saltedpeanuts is replaced with the Velocity
    property reference ${packageName}. When the user generates a project, this
    is in turn replaced by his or her choice of a package.
  custom properties
    You may identify additional strings that should be replaced by parameters.
    To add custom properties, you must use the propertyFile parameter to specify
    a property file. See the documentation for propertyFile for the details.

  Note that you may need to edit the results of this goal. This goal has no way
  to exclude unwanted files, or add copyright notices to the Velocity templates,
  or add more complex elements to the archetype metadata file.

  This goal also generates a simple integration-test that exercises the
  generated archetype.


在项目的pom文件中,增加插件.


然后在项目路径下执行
E:\workspace\songod>mvn archetype:create-from-project

Maven会根据这个项目生成一个模板项目.(target\generated-sources\archetype)

进入模板项目,打包、安装模板项目.
E:\workspace\songod\target\generated-sources\archetype>mvn clean install

在控制台可以看到如下日志
[INFO] Installing E:\workspace\songod\target\generated-sources\archetype\target\songod-archetype-0.0.1-SNAPSHOT.jar to C:\Users\new\.m2\repository\com\vv\songod-archetype\0.0.1-SNAPSHOT\songod-archetype-0.0.1-SNAPSHOT.jar
[INFO] Installing E:\workspace\songod\target\generated-sources\archetype\pom.xml to C:\Users\new\.m2\repository\com\vv\songod-archetype\0.0.1-SNAPSHOT\songod-archetype-0.0.1-SNAPSHOT.pom

可以看到这个模板项目作为
songod-archetype-0.0.1-SNAPSHOT.jar已经安装到了本地仓库.
如果公司内部使用,可以将其发布到Nexus私服

使用刚才的模板创建新项目.
因为模板是SNAPSHOT的,所以需要勾选 Include snapshot archetypes 选项.
找到刚才制作的模板,创建项目.


新项目创建之后,spring、springmvc和MyBatis都配置好了.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-1974624/,如需转载,请注明出处,否则将追究法律责任。

下一篇: 初探Lucene
请登录后发表评论 登录
全部评论

注册时间:2013-10-19

  • 博文量
    621
  • 访问量
    5949779