1、前言
快速搭建框架,统一结构风格和编码风格。
2、老项目根目录下执行
当然自己也可以新建一个项目
mvn archetype:create-from-project
3、删除target目录下不必要的文件
target、iml、log等
4、修改文件archetype-metadata.xml
目录:example-archetype.src.main.resources.META-INF.maven
需要哪些文件,就保留哪些fileSet节点
module:表示子工程
fileSet:表示文件目录
<module id="${rootArtifactId}-common" dir="__rootArtifactId__-common" name="${rootArtifactId}-common">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-job" dir="__rootArtifactId__-job" name="${rootArtifactId}-job">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-model" dir="__rootArtifactId__-model" name="${rootArtifactId}-model">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-service" dir="__rootArtifactId__-service" name="${rootArtifactId}-service">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.factories</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-web" dir="__rootArtifactId__-web" name="${rootArtifactId}-web">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/assembly</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/webapp</directory>
<includes>
<include>**/*.html</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xlsx</include>
<include>**/*.sh</include>
<include>**/*.factories</include>
<include>**/*.jar</include>
<include>**/*.xls</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/webapp</directory>
<includes>
<include>**/*.jpg</include>
<include>**/*.css</include>
<include>**/*.svg</include>
<include>**/*.ttf</include>
<include>**/*.png</include>
<include>**/*.js</include>
</includes>
</fileSet>
</fileSets>
</module>
5、修改项目名称
目录:target/generated-sources/archetype/src/main/resources/archetype-resources
和module的dir="__rootArtifactId__-web"保持一致
6、修改子工程之间的依赖名称
<dependency>
<groupId>com.test</groupId>
<artifactId>${rootArtifactId}-service</artifactId>
<version>${parent.version}</version>
</dependency>
7、生成脚手架
/target/generated-sources/archetype目录下执行:
没有maven私库
mvn clean install
有maven私库
mvn clean install deploy
仓库下会生成一个archetype-catalog.xml文件
<archetypes>
<archetype>
<groupId>com.test</groupId>
<artifactId>test-archetype</artifactId>
<version>V1.0</version>
<description></description>
</archetype>
</archetypes>
8、根据脚手架生成新的项目
mvn archetype:generate -B -DarchetypeCatalog=local -DarchetypeGroupId=com.test -DarchetypeArtifactId=test-archetype -DarchetypeVersion=V1.0 -DgroupId=com.test -DartifactId=test -Dversion=1.0-SNAPSHOT -Dpackage=com.test
- -DarchetypeGroupId=com.test
- 上面archetype-catalog.xml文件中的groupId
- -DarchetypeArtifactId=test-archetype
- 上面archetype-catalog.xml文件中的artifactId
- -DarchetypeVersion=V1.0
- 上面archetype-catalog.xml文件中的version
- -DgroupId=com.test
- 要生成新的工程的groupId
- -DartifactId=test
- 要生成新的工程的artifactId
- -Dversion=1.0-SNAPSHOT
- 要生成新的工程的version
- -Dpackage=com.test
- 要生成新的工程的package