iT邦幫忙

2025 iThome 鐵人賽

DAY 9
0
Software Development

我們與Maven的距離系列 第 9

Day08 - Standard Layout and Super POM

  • 分享至 

  • xImage
  •  

前言

Maven有個設計理念「約定大於配置」(Convention Over Configuration),做人有懶的美德能用預設就用預設最好通通都不用設定,所以該怎麼做呢?首先你要有一個約定好的

  • 專案夾資料結構
  • 預設的設定檔
  • 預設下載jar檔的來源
  • 預設執行的工作流程

Standard Layout

我們知道在java的世界裡,

└───maven-project
    ├───pom.xml
    ├───README.txt (放置關於專案的資訊)
    ├───NOTICE.txt (使用相關第三方套件訊息)
    ├───LICENSE.txt (此專案的License)
    └───src
        ├───main
        │   ├───java
        │   ├───resources
        │   ├───filters
        │   └───webapp
        ├───test
        │   ├───java
        │   ├───resources
        │   └───filters
        ├───it (保留給integration test使用之資料夾)
        ├───site (網站文件資料夾)
        └───assembly (binary 打包設定檔路徑)
    └───target (執行maven 相關作業會產生的結果會放置於資料夾)    

Super POM

除了專案目錄的pom.xml外,還有一個預設的super pom.xml,所有的pom都會繼承於super pom,他被藏在你安裝的maven資料夾路徑中
https://ithelp.ithome.com.tw/upload/images/20250923/20128084T61XRYVA9w.png
開啟壓縮檔來看一下
https://ithelp.ithome.com.tw/upload/images/20250923/20128084iQBoNIOWox.png
裡面放置著很多預設的配置,詳細可以參考官網-Super POM,像是build tag中預設的資料夾路徑

<build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
     <!-- 其他略 -->
</build>

預設jar檔來源下載路徑

   <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

Reference


上一篇
Day07 - POM
系列文
我們與Maven的距離9
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言