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包形式。


  
  
  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

猜你喜欢

转载自blog.csdn.net/qq_42239765/article/details/83652678