Maven插件和细节

1、父工程统一版本号

 1 <!-- 集中定义依赖版本号 -->
 2     <properties>
 3         <junit.version>4.12</junit.version>
 4         <spring.version>4.1.3.RELEASE</spring.version>
 5     </properties>
 6 
 7 <!-- 只定义依赖的版本,并不实际依赖 -->
 8     <dependencyManagement>
 9         <dependencies>
10             <!-- 单元测试 -->
11             <dependency>
12                 <groupId>junit</groupId>
13                 <artifactId>junit</artifactId>
14                 <version>${junit.version}</version>
15                 <scope>test</scope>
16             </dependency>
17             <!-- Spring -->
18             <dependency>
19                 <groupId>org.springframework</groupId>
20                 <artifactId>spring-context</artifactId>
21                 <version>${spring.version}</version>
22             </dependency>
23             <dependency>
24                 <groupId>org.springframework</groupId>
25                 <artifactId>spring-beans</artifactId>
26                 <version>${spring.version}</version>
27             </dependency>
28             <dependency>
29                 <groupId>org.springframework</groupId>
30                 <artifactId>spring-webmvc</artifactId>
31                 <version>${spring.version}</version>
32             </dependency>
33             <dependency>
34                 <groupId>org.springframework</groupId>
35                 <artifactId>spring-test</artifactId>
36                 <version>${spring.version}</version>
37                 <scope>provided</scope>
38             </dependency>
39             <dependency>
40                 <groupId>org.springframework</groupId>
41                 <artifactId>spring-jdbc</artifactId>
42                 <version>${spring.version}</version>
43             </dependency>
44             <dependency>
45                 <groupId>org.springframework</groupId>
46                 <artifactId>spring-aspects</artifactId>
47                 <version>${spring.version}</version>
48             </dependency>
49         </dependencies>
50     </dependencyManagement>

指定插件版本和使用

 1 父工程POM
 2 <pluginManagement>  加上这个标签表示只指定版本,子工程还需要指定,只不过不需要版本
 3     <plugins>
 4         <!-- 配置Tomcat插件 -->
 5         <plugin>
 6             <groupId>org.apache.tomcat.maven</groupId>
 7             <artifactId>tomcat7-maven-plugin</artifactId>
 8             <version>2.2</version>
 9         </plugin>
10     </plugins>
11 </pluginManagement>
12 
13 子工程
14 <!-- 添加tomcat插件 -->
15     <build>
16         <plugins>
17             <plugin>
18                 <groupId>org.apache.tomcat.maven</groupId>
19                 <artifactId>tomcat7-maven-plugin</artifactId>
20                 <configuration>
21                     <port>8080</port>
22                     <path>/</path>
23                 </configuration>
24             </plugin>
25         </plugins>
26     </build>

2、指定编译环境-JDK版本(1.8为例)

 1 <build>
 2         <plugins>
 3             <plugin>
 4                 <groupId>org.apache.maven.plugins</groupId>
 5                 <artifactId>maven-compiler-plugin</artifactId>
 6                 <version>3.7.0</version>
 7                 <configuration>
 8                     <source>1.8</source>
 9                     <target>1.8</target>
10                     <encoding>UTF-8</encoding>
11                 </configuration>
12             </plugin>
13         </plugins>
14 </build>

3、src/main/java下的文件如果打jar包,默认只会编译*.java的文件,忽略其他类型文件

例如:mybatis的mapping映射文件不会打包,则报错

解决:

 1 <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
 2     <build>
 3         <resources>
 4             <resource>
 5                 <directory>src/main/java</directory>
 6                 <includes>
 7                     <include>**/*.properties</include>
 8                     <include>**/*.xml</include>
 9                 </includes>
10                 <filtering>false</filtering>
11             </resource>
12         </resources>
13     </build>

猜你喜欢

转载自www.cnblogs.com/webyyq/p/8874411.html