iT邦幫忙

2025 iThome 鐵人賽

DAY 10
0
Software Development

我們與Maven的距離系列 第 30

Day29 - IntelliJ IDEA Integration with Maven

  • 分享至 

  • xImage
  •  

前言

從開始到現在我們主要的操作都是透過Command Line進行,目的是要讓你深刻了解開發部署過程有多麼的繁瑣,一方面有了深刻的體悟一方面也順便熟悉了操作語法與流程,在使用IDE這個屠龍刀才能游刃有餘,今天我們就來看看Intellij如何集成Maven的吧!

1. 創建Maven專案

選取路徑File/New/Project
https://ithelp.ithome.com.tw/upload/images/20251014/20128084ZQKlS3Fh4G.png
選擇Maven Archetype
https://ithelp.ithome.com.tw/upload/images/20251014/20128084Pa1QNo9eWU.png
JDK:Intellij也幫你整合各家JDK供你下載
https://ithelp.ithome.com.tw/upload/images/20251014/201280848uHSkZnLHe.png
catalog選取internal可以看到我們常用的archetype,catalog選取maven則會看到很多第三方撰寫的archetype
https://ithelp.ithome.com.tw/upload/images/20251014/20128084DkDm0PANzr.png
設定advanced setting
https://ithelp.ithome.com.tw/upload/images/20251014/201280842G67SNLrsa.png
創建完成後專案結構
https://ithelp.ithome.com.tw/upload/images/20251014/20128084PCGWNGD9Nb.png

2. 安裝Maven Extension

選取路徑Settings/Plugins/Marketplace
https://ithelp.ithome.com.tw/upload/images/20251014/20128084NJNJPPWayD.png

3. Maven設置

選取路徑Settings/Build,Exception,Deployment/Build/Maven,Intellij預設就幫你綁定最新的Maven,相關設定可以自行切換路徑
https://ithelp.ithome.com.tw/upload/images/20251014/20128084Xf8chp8RTq.png
點選Runner可以自行設定VM Option與環境變數
https://ithelp.ithome.com.tw/upload/images/20251014/20128084hw2S5cjDEn.png

4. Maven基本使用

點選側邊欄m,可以看到所有的生命週期與plugin的goal,點兩下就可以執行了,再也不需要記得語法
https://ithelp.ithome.com.tw/upload/images/20251014/20128084hCU0Ozy67S.png
plugin的goal右鍵可以設定執行時的參數
https://ithelp.ithome.com.tw/upload/images/20251014/20128084aJPwkdsilT.png
https://ithelp.ithome.com.tw/upload/images/20251014/20128084oVbj3mLdDB.png
透過Reload All Maven Project 更新dependency與plugin
https://ithelp.ithome.com.tw/upload/images/20251014/20128084JMdGOJ0GLm.png

pom.xml可以透過右鍵generate/Dependency搜尋添加依賴
https://ithelp.ithome.com.tw/upload/images/20251014/20128084AoZaSqYUIU.png

https://ithelp.ithome.com.tw/upload/images/20251014/20128084j1KpW4mY3s.png

5. 匯入Maven專案

我們以既有的Springboot專案進行匯入
https://ithelp.ithome.com.tw/upload/images/20251014/20128084jMt0kVoNL8.png
選取maven
https://ithelp.ithome.com.tw/upload/images/20251014/20128084TkLEOX178G.png
測試執行,出現JDK1.8不匹配的問題
https://ithelp.ithome.com.tw/upload/images/20251014/201280843cUu5WJovF.png
File/Project Structure設定SDK與Language為合適版本21
https://ithelp.ithome.com.tw/upload/images/20251014/20128084m3JlEaLNjs.png
測試執行成功
https://ithelp.ithome.com.tw/upload/images/20251014/20128084mCP1a4nuJq.png

小結

本日簡單的介紹Intellij整合Maven的相關功能,IDE透過UI點選簡化了指令輸入的繁瑣,有了過往的maven的基本功,使用IDE後就能效率倍增

Reference


上一篇
Day28 - Maven Wrapper
下一篇
Day30 - Visual Studio Code Integration with Maven
系列文
我們與Maven的距離31
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言