maven專案的檔案目錄結構以及相關檔案的作用
一、說到maven專案,我們首先要提及到的就是當中的pom檔案,相信這個對於大家來說一點都不陌生。這裡我也詳細介紹一下關於pom檔案的內容。每次我們通過eclipse或者idea生成一個maven專案時,專案的根目錄下都會生成一個pom.xml的maven配置檔案。
1、以下的配置檔案是pom.xml中的最基本配置檔案,主要包含:project root,modelVersion --這個值通常被設定為4.0.0,goroupId--表示專案組Id,artifactId--專案Id,version--專案版本號,包含以上內容,已經是一個完整的pom配置檔案了。其中還有其他選項分別表示編碼方式為utf-8,打包方式為war包形式。
[html]
view plain
copy
print
?
- <code class="language-html"><?xml version="1.0" encoding="UTF-8"?> <!-- 表示通過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/maven-v4_0_0.xsd">
- <
- <artifactId>irp</artifactId>
- <groupId>com.grg</groupId>
- <version>1.0</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.test</groupId>
- <artifactId>chapter1</artifactId>
- <packaging>war</packaging>
- <version>1.0</version></code>
-
<?xml version="1.0" encoding="UTF-8"?>
<!-- 表示通過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/maven-v4_0_0.xsd">
-
<parent>
-
<artifactId>irp
</artifactId>
-
<groupId>com.grg
</groupId>
-
<version>1.0
</version>
-
</parent>
-
<modelVersion>4.0.0
</modelVersion>
-
<groupId>com.test
</groupId>
-
<artifactId>chapter1
</artifactId>
-
<packaging>war
</packaging>
-
<version>1.0
</version>
2、通過以上的設定,可以設定原始碼和編譯的輸出的JDK版本,這個根據自己的JDK版本號來進行填寫
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins
</groupId>
-
<artifactId>maven-compiler-plugin
</artifactId>
-
<version>${maven-compiler-plugin.version}
</version>
-
<configuration>
-
<source>${jdk.version}
</source>
<!-- 原始碼的JDK版本 -->
-
<target>${jdk.version}
</target>
<!-- 編譯的JDK版本 -->
-
<encoding>UTF-8
</encoding>
<!-- 設定編譯的字符集編碼和環境編碼 -->
-
<compilerArguments>
-
<extdirs>src/main/webapp/WEB-INF/lib
</extdirs>
-
</compilerArguments>
-
</configuration>
-
</plugin>
-
<plugins>
-
<buile>
3、maven中的外掛:build plugins,在構建專案的時候執行,被配置在<build><plugins><plugins><build>元素當中,Reporting plugins則被配置在<reporting><plugins><plugins><reporting>。以下就是配置tomcat外掛的配置檔案
-
<plugin>
-
<groupId>org.apache.tomcat.maven
</groupId>
-
<artifactId>tomcat7-maven-plugin
</artifactId>
-
<version>2.1
</version>
-
<configuration>
-
<port>8989
</port>
-
<uriEncoding>utf-8
</uriEncoding>
-
<path>/
</path>
-
<contextFile>src/main/webapp/WEB-INF/context.xml
</contextFile>
-
</configuration>
-
</plugin>
4、maven中的依賴:通過標籤<dependency>進行依賴jar包的定義,例子如下:
-
<dependency>
-
<groupId>org.springframework
</groupId>
-
<artifactId>spring-core
</artifactId>
-
<version>${spring.version}
</version>
-
</dependency>
二、關於pom.xml配置檔案的主要功能介紹基本就這麼多,接著我們介紹一下關於maven專案的其他目錄結構檔案以及其相關含義
/src/main/java/ java原始碼
/src/main/resource java各種配置檔案,資原始檔
/src/main/webapp web各種原始檔,格式檔案如css,js,html,jsp等
/src/test/java java測試程式碼
/target 檔案編譯過程中生成的.class檔案,jar,war等
此文章為原創檔案,如需轉載,麻煩說明出處https://blog.csdn.net/funnychaos/article/details/80144017