1. 程式人生 > >maven專案的檔案目錄結構以及相關檔案的作用

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 ?
  1. <code class="language-html"><?xml version="1.0" encoding="UTF-8"?>            <!--  表示通過UTF-8進行編碼   -->
      
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  4.     <
    parent>  
  5.         <artifactId>irp</artifactId>  
  6.         <groupId>com.grg</groupId>  
  7.         <version>1.0</version>  
  8.     </parent>  
  9.     <modelVersion>4.0.0</modelVersion>             
  10.     <groupId>com.test</groupId>  
  11.     <artifactId>chapter1</artifactId>  
  12.     <packaging>war</packaging>  
  13.     <version>1.0</version></code>  

   
  1. <?xml version="1.0" encoding="UTF-8"?> <!-- 表示通過UTF-8進行編碼 -->
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4. <parent>
  5. <artifactId>irp </artifactId>
  6. <groupId>com.grg </groupId>
  7. <version>1.0 </version>
  8. </parent>
  9. <modelVersion>4.0.0 </modelVersion>           
  10. <groupId>com.test </groupId>
  11. <artifactId>chapter1 </artifactId>
  12. <packaging>war </packaging>
  13. <version>1.0 </version>

2、通過以上的設定,可以設定原始碼和編譯的輸出的JDK版本,這個根據自己的JDK版本號來進行填寫


  
  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins </groupId>
  5. <artifactId>maven-compiler-plugin </artifactId>
  6. <version>${maven-compiler-plugin.version} </version>
  7. <configuration>
  8. <source>${jdk.version} </source> <!-- 原始碼的JDK版本 -->
  9. <target>${jdk.version} </target> <!-- 編譯的JDK版本 -->
  10. <encoding>UTF-8 </encoding> <!-- 設定編譯的字符集編碼和環境編碼 -->
  11. <compilerArguments>
  12. <extdirs>src/main/webapp/WEB-INF/lib </extdirs>
  13. </compilerArguments>
  14. </configuration>
  15. </plugin>
  16. <plugins>
  17. <buile>

3、maven中的外掛:build plugins,在構建專案的時候執行,被配置在<build><plugins><plugins><build>元素當中,Reporting plugins則被配置在<reporting><plugins><plugins><reporting>。以下就是配置tomcat外掛的配置檔案


  
  1. <plugin>
  2. <groupId>org.apache.tomcat.maven </groupId>
  3. <artifactId>tomcat7-maven-plugin </artifactId>
  4. <version>2.1 </version>
  5. <configuration>
  6. <port>8989 </port>
  7. <uriEncoding>utf-8 </uriEncoding>
  8. <path>/ </path>
  9. <contextFile>src/main/webapp/WEB-INF/context.xml </contextFile>
  10. </configuration>
  11. </plugin>

4、maven中的依賴:通過標籤<dependency>進行依賴jar包的定義,例子如下:


  
  1. <dependency>
  2. <groupId>org.springframework </groupId>
  3. <artifactId>spring-core </artifactId>
  4. <version>${spring.version} </version>
  5. </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