创建基于maven的项目模版
2013-11-22 15:47
260 查看
我们在实际工作中 ,有些项目的架构是相似的,例如基于 restful的接口项目,如果每次都重新搭建一套架构或者通过拷贝建立一个项目难免有些得不偿失,这里我们可以用maven的archtype建立项目模版来解决 。
创建maven archetype的步骤:
archetype组成:
archetype.xml (src/main/resources/META-INF/maven/)
框架本身的源码和资源文件模版 src/main/resources/archetype-resources/
框架本身的pom文件模版 src/main/resources/archetype-resources/
生成框架的这个archetype的pom
archetype的pom,这里面的groupId,artifactId,version会在执行maven 的archetype generate 时显示
其中pom中的 id应该和archetype.xml里面的artifactId一致
pom.xml
archetype.xml
标签说明:
<allowPartial>true</allowPartial> 该标签说明在一个已经存在的项目中依然可以运行 mvm archetype
<sources>, <resources>, <testSources>, <testResources> , <siteResources>代表项目的不同部分
<sources> = src/main/java
<resources> = src/main/resources
<testSources> = src/test/java
<testResources> = src/test/resources
<siteResources> = src/site
<sources>,<testSources>包含<source>,这个表示里面的一个源码文件
<testResources> a <siteResources>包含<resource>,这个表示里面是一个资源文件
创建一个架构的pom模版
配置完后,执行
mvn install完成安装
安装后,执行
mvn archetype:generate \
-DarchetypeGroupId=<archetype-groupId> \
-DarchetypeArtifactId=<archetype-artifactId> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<my.groupid> \
-DartifactId=<my-artifactId>
可以完成该架构的安装
eg:
mvn archetype:generate \
-DarchetypeGroupId=com.taobao.data.arch \
-DarchetypeArtifactId=jersey-quickstart \
-DarchetypeVersion=1.0-SNAPSHOT \
-DgroupId=com.taobao.data.zl \
-DartifactId=testjersey
创建maven archetype的步骤:
archetype组成:
archetype.xml (src/main/resources/META-INF/maven/)
框架本身的源码和资源文件模版 src/main/resources/archetype-resources/
框架本身的pom文件模版 src/main/resources/archetype-resources/
生成框架的这个archetype的pom
archetype的pom,这里面的groupId,artifactId,version会在执行maven 的archetype generate 时显示
其中pom中的 id应该和archetype.xml里面的artifactId一致
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my.groupId</groupId> <artifactId>quickstart</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> </project>
archetype.xml
<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd"> <id>quickstart</id> <sources> <source>src/main/java/App.java</source> </sources> <testSources> <source>src/test/java/AppTest.java</source> </testSources> </archetype>
标签说明:
<allowPartial>true</allowPartial> 该标签说明在一个已经存在的项目中依然可以运行 mvm archetype
<sources>, <resources>, <testSources>, <testResources> , <siteResources>代表项目的不同部分
<sources> = src/main/java
<resources> = src/main/resources
<testSources> = src/test/java
<testResources> = src/test/resources
<siteResources> = src/site
<sources>,<testSources>包含<source>,这个表示里面的一个源码文件
<testResources> a <siteResources>包含<resource>,这个表示里面是一个资源文件
创建一个架构的pom模版
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <version>${version}</version> <packaging>jar</packaging> <name>A custom project</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> ${artifactId}和${groupId} 将在执行maven archetype 里面提示
配置完后,执行
mvn install完成安装
安装后,执行
mvn archetype:generate \
-DarchetypeGroupId=<archetype-groupId> \
-DarchetypeArtifactId=<archetype-artifactId> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<my.groupid> \
-DartifactId=<my-artifactId>
可以完成该架构的安装
eg:
mvn archetype:generate \
-DarchetypeGroupId=com.taobao.data.arch \
-DarchetypeArtifactId=jersey-quickstart \
-DarchetypeVersion=1.0-SNAPSHOT \
-DgroupId=com.taobao.data.zl \
-DartifactId=testjersey
相关文章推荐
- 基于maven使用IDEA创建多模块项目-很详细
- 基于maven使用IDEA创建多模块项目
- IDEA环境下创建基于Maven的Web项目出现找不到资源文件的问题
- 如何使用IntelliJ IDEA 创建基于Maven构建的Web项目的过程
- 基于maven使用IDEA创建多模块项目
- 【spark】创建一个基于maven的spark项目所需要的pom.xml文件模板
- 基于maven创建和部署Webx项目
- MyEclipse创建基于Maven的Web项目去掉项目名后缀方案(Maven Webapp)
- 基于IntelliJ IDEA上创建Maven Spring MVC项目web.xml文件解读
- 基于maven的springmvc项目创建
- 基于maven使用IDEA创建多模块项目
- Maven2 根据项目生成模版项目,并使用该模板批量创建工程
- Maven2 根据项目生成模版项目,并使用该模板批量创建工程
- 图文介绍IntelliJ IDEA 创建基于Maven构建的Web项目
- Java Web学习系列——创建基于Maven的Web项目
- 关于 基于maven创建的项目jsp页面无法加载css、js、图片的问题
- 基于maven使用IDEA创建多模块项目
- 创建基于Maven的多模块项目
- 基于maven使用IDEA创建多模块项目
- 基于maven使用IDEA创建springboot多模块项目