建立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 建立web專案MavenWeb
- Maven建立Java專案MavenJava
- archetype:create-from-project命令建立maven模板工程(自定義專案模板並且上載到maven私服)ProjectMaven
- 建立Maven專案出錯Maven
- 建立自定義專案模板
- 如何用Maven建立web專案MavenWeb
- maven 專案的建立入門Maven
- Maven安裝本地的jar包和建立帶模板的自定義專案MavenJAR
- 用maven建立專案及maven常用命令Maven
- Maven建立Web應用程式專案MavenWeb
- Maven+myeclipse 建立聚合專案MavenEclipse
- Maven通過命令建立web專案MavenWeb
- 使用maven2快速建立專案Maven
- 建立Maven專案出錯 pom出錯Maven
- Springboot建立maven多模組專案Spring BootMaven
- Maven建立專案遇到導包錯誤:Maven
- Maven配置-使用Maven建立WEB專案支援Tomcat目錄部署MavenWebTomcat
- 如何建立一個Maven專案(eclipse版本)MavenEclipse
- 如何建立+管理maven、匯入web專案、xmlMavenWebXML
- IDEA--Maven建立WEB分模組專案IdeaMavenWeb
- 使用Maven命令列快速建立專案骨架(archetype)Maven命令列
- 【Maven實戰技巧】「外掛使用專題」Maven-Archetype外掛建立自定義maven專案骨架Maven
- IntelliJ IDEA中建立Web聚合專案(Maven多模組專案)IntelliJIdeaWebMaven
- maven學習總結(七)——eclipse中使用Maven建立Web專案MavenEclipseWeb
- IDEA建立Maven專案中踩過的坑IdeaMaven
- 原創一看便知、Maven建立web專案MavenWeb
- 在idea中利用spingboot建立maven專案IdeabootMaven
- eclipse 建立maven專案設定預設jdk版本EclipseMavenJDK
- Maven 專案文件Maven
- 使用命令列建立Maven的專案或模組目錄命令列Maven
- 使用IntelliJ IDEA 15和Maven建立Java Web專案IntelliJIdeaMavenJavaWeb
- 通過互動式命令從github拉取專案模板並建立新專案Github
- MyEclipse - 通過Maven建立WebApp專案時,生成的專案名中總是包含Maven Webapp的問題EclipseMavenWebAPP
- JN專案配置-公司是maven專案Maven
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven
- maven使用mvn archetype:generate命令建立專案骨架遇到的問題Maven
- Maven教程(Eclipse配置及maven專案)MavenEclipse