建立Maven模板專案
假如已經存在了一個專案,
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都配置好了.
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Maven 專案模板Maven
- 建立Maven專案出錯Maven
- 建立自定義專案模板
- maven 專案的建立入門Maven
- Maven安裝本地的jar包和建立帶模板的自定義專案MavenJAR
- 用maven建立專案及maven常用命令Maven
- Maven建立Web應用程式專案MavenWeb
- Springboot建立maven多模組專案Spring BootMaven
- 建立Maven專案出錯 pom出錯Maven
- Maven建立專案遇到導包錯誤:Maven
- 在idea中利用spingboot建立maven專案IdeabootMaven
- 如何建立一個Maven專案(eclipse版本)MavenEclipse
- IDEA建立Maven專案中踩過的坑IdeaMaven
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven
- 如何建立+管理maven、匯入web專案、xmlMavenWebXML
- 【Maven實戰技巧】「外掛使用專題」Maven-Archetype外掛建立自定義maven專案骨架Maven
- IDEA設定預設Maven(使用idea maven archetype建立專案時,專案建立慢或者不完整,缺失部分目錄)IdeaMaven
- Idea intellij jdk 1.7通過maven建立Springboot專案IdeaIntelliJJDKMavenSpring Boot
- MyEclipse - 通過Maven建立WebApp專案時,生成的專案名中總是包含Maven Webapp的問題EclipseMavenWebAPP
- Maven 專案文件Maven
- Maven教程(Eclipse配置及maven專案)MavenEclipse
- 通過互動式命令從github拉取專案模板並建立新專案Github
- 使用命令列建立Maven的專案或模組目錄命令列Maven
- maven使用mvn archetype:generate命令建立專案骨架遇到的問題Maven
- Idea Java Maven建立專案,新增依賴,引用本地jar,打包jarIdeaJavaMavenJAR
- maven 專案轉化成 gradle 專案實踐MavenGradle
- Java Maven專案推送到 Maven 中央倉庫JavaMaven
- Maven專案打jar包MavenJAR
- Maven 構建 Java 專案MavenJava
- 專案新建模板
- 建立Maven專案,提示'settings.xml' has syntax errors less... (Ctrl+F1) Inspection info: Inspects a Maven...MavenXMLError
- C#如何建立一個可快速重複使用的專案模板C#
- React專案模板-從專案搭建到部署React
- Maven專案無法引入 Maven Dependencies Libraries 問題Maven
- IDEA搭建和部署Maven專案IdeaMaven
- 使用Maven構建Java專案MavenJava
- maven專案增加web.xmlMavenWebXML
- Maven中POM專案物件模型Maven物件模型
- java專案打包(maven+原生)JavaMaven