下面是我新建一個maven項目后生產的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>com.zjf.www</groupId>
<artifactId>maven-webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>maven-webapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>1.2.6</version>
<type>jar</type>
<url>http://www.springframework.org/</url>
</dependency>
</dependencies>
<build>
<finalName>maven-webapp</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
本人也是是懂非懂,網上查了些資料大概講述一下。
<modelVersion>4.0.0</modelVersion> modelVersion:pom文件的模型版本 為4.0.0
<groupId>com.zjf.www</groupId> groupId 組織名稱 com.zjf.www 是我創建項目用的文件路徑 即公司網址
<artifactId>maven-webapp</artifactId> artifactId 項目名稱 是我新建的maven項目名稱
<version>0.0.1-SNAPSHOT</version> version: artifact模塊的版本
<packaging>war</packaging> packaging:項目打包的后綴,war是web項目發布用的,默認為jar
<name>maven-webapp Maven Webapp</name>
<url>http://www.example.com</url> name和url:相當於項目描述,可刪除
group id + artifact id +version :項目在倉庫中的坐標
第二部分,引入jar包
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
這是創建項目時自動生成的,將junit-4.11.jar引入到項目中。
<dependencies> 是引入jar包的跟目錄 所有引進jar都在這個標簽里面 增加<dependency>
dependency:引入資源jar包到本地倉庫,一對dependency標簽就引進一個jar包
同理 group id+artifact id+version:資源jar包在倉庫中的坐標
scope:作用范圍,test指該jar包僅在maven測試時使用,發布時會忽略這個包。需要發布的jar包可以忽略這一配置
第三部分,構建項目
build:項目構建時的配置
finalName:在瀏覽器中的訪問路徑,如果將它改成helloworld,再執行maven--update,這時運行項目的訪問路徑是
http://localhost:8080/helloworld/ 而不是項目名的 http://localhost:8080/test
plugins:插件
group id+artifact id+version:插件在倉庫中的坐標
configuration:設置插件的參數值