Why is the structure of the maven project like this

Why is the structure of the maven project like this

Purpose of this article

   Followed by a detailed explanation of the powerful scope tags in maven .
   From the first time I came into contact with maventhe project, I was curious why maventhe structure of the project src/main/java, src/main/resources, target, pom.xmlis as follows:

src
----main
--------java   // 开发的java代码全都放在这里  
--------resources   //xml文件、配置文件等
target    // maven项目编译打包的目标目录
pom.xml   // maven项目的依赖配置

  Although I know there must be a configuration to specify these directories, but I don't know where it is. Only recently did I realize this truth.

text

   In fact, this structure is mavendefined in a file.
   When we use mavenit, we will specify maventhe directory. For example, the one below: There are many dependent jars in
insert image description here
   maventhe package, which will be referenced when the project uses the current one.    In the corresponding package, there is a file with such a paragraph. as follows:libmaven
/lib/maven-model-builder-3.3.3.jarpom-4.0.0.xm

<build>
    <!--1.编译的目录在项目的target文件夹中-->
    <directory>${project.basedir}/target</directory>
    <!--2.源码编译后存储到target/classes文件夹中-->
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <!--3.输出项目的名称-->
    <finalName>${project.artifactId}-${project.version}</finalName>
    <!--4.测试类源码编译后存储到/target/test-classes-->
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <!--5.源码的目录/src/main/java-->
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <resources>
      <resource>
          <!--6.项目的配置文件目录/src/main/resources-->
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
    <pluginManagement>
      <!-- NOTE: These plugins will be removed from future versions of the super POM -->
      <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
       <!-- maven的这个超级pom默认引用的插件,我们所有的项目都能够继承这些,但是通过上边的提示,
 		    可以大概理解,这些插件将来会从超级pom里移除,因为看起来不够友好,有的项目开发中也会
			依赖,导致冲突-->
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  As you can see from the above figure, maventhe structure of the project mavenis inherited from this configuration.
  In the next article, when you learn about maven citing dependencies, if there are multiple dependencies, how does maven do dependency mediation, maven's dependency mediation mechanism .

Guess you like

Origin blog.csdn.net/wohaqiyi/article/details/119882077