自定义骨架
Maven项目有自己的目录结构,手动创建比较麻烦。
骨架:archetype ==> 约定一套通用的项目目录,帮助快速初始化项目中的目录结构
- 建web项目
首先创建一个maven web项目,此项目在创建时,可以先用默认的webapp骨架,并更改目录结构如下:
<!-- web.xml改动如下 -->
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
</web-app>
<!-- pom.xml改动如下 注意:打包格式 为war -->
<?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>com.zhj.test</groupId>
<artifactId>webapp_zhj</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- jstl 支持 -->
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<!-- servlet编译环境 -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- jsp编译环境 -->
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- mybatis 依赖 -->
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<!-- mysql驱动 依赖 -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
- 生成骨架
在项目目录下执行:mvn archetype:create-from-project
会产生 “target
”目录。务必删除其中一些无用目录,其中是当前项目的状态,会影响基于此骨架创建的项目。
再删除 xxx.iml
文件
- 安装骨架
注意:在 target > generated-sources > archetype
目录下执行:
mvn install
即可将骨架安装到本地maven仓库
- 使用骨架
添加自己的骨架,基于自己的骨架创建项目
C:\Users\Lenovo\.IntelliJIdea2018.2\system\Maven\Indices\UserArchetypes.xml
其中记录了 idea中 会显示在骨架列表中的 自定义骨架内容