0.约定
原型:artchetype
1.创建原型pom文件
创建文件夹service-archetype
,在该文件夹下创建pom.xml
文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>cn.jastz</groupId><!--原型 groupId -->
<artifactId>service-archetype</artifactId><!--原型 artifactId -->
<version>1.0-SNAPSHOT</version><!--原型 version -->
<packaging>jar</packaging>
</project>
2.创建原型描述文件
创建如下目录及文件:
service-archetype
|-- pom.xml
`-- src
`-- main
`-- resources
-- META-INF
`-- maven
`--archetype.xml
在目录service-archetype/src/main/resources/META-INF/maven
下创建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>
3.创建原型相关文件及原型pom文件
创建如下目录结构及文件
service-archetype
|-- pom.xml
`-- src
`-- main
`-- resources
|
`-- archetype-resources
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java
在service-archetype/src/main/resources/archetype-resources
下创建pom.xml
文件,该文件是原型的模板文件,具体内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>${artifactId}</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.jastz</groupId>
<artifactId>payment-entity</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>me.jastz</groupId>
<artifactId>common-utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
</plugins>
</build>
</project>
在service-archetype/src/main/resources/archetype-resources
目录下创建src
目录、子目录及文件,这些文件即是根据原型生成的项目所包含的文件。
4.安装原型和运行原型插件
运行命令安装
mvn install
5. idea中设置原型
File -> New -> Project... -> Maven -> 选中 Create from archetype -> 点击 Add Archetype... 按钮 -> 输入 原型 groupId 、原型 artifactId 、原型 version