IDEA解決Maven建立新專案不載入jar包問題
一、安裝IDEA
引用別人安裝心得 安裝
二、新建maven專案
1、建立maven project 選擇quickstart型別,點選Next
2、輸入groupId和ArtifactId 點選Next
3、選擇maven庫及配置檔案 如圖所示
4、建立settings.xml 檔案存放到 C:\Users\yanlz\.m2\repository 如圖所示:
<?xml version="1.0"?> <settings> <localRepository>C:\Users\yanlz\.m2\repository</localRepository><!--需要改成自己的maven的本地倉庫地址--> <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://maven.oschina.net/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://maven.oschina.net/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile></profiles> </settings>
5、修改專案名稱 這裡吐槽一下 IDEA建立專案直接把“-”去掉了 每次都需要手動加上 點選Next
6、如圖所示
三、建立專案時沒有程式碼目錄和資源目錄
建立src/main/java 並標記為原始碼檔案
建立src/main/resoures 並標記資原始檔夾
方法一、直接右鍵 標記
選擇java目錄右鍵 Mark Directory as --> Sources Root
選擇resources目錄右鍵 Mark Directory as --> Resources Root方法二、選擇專案 --> Project Structure 跳出面板 --> 選擇 Modules --> Sources --> 選擇資料夾 -->標記
四、在pom.xml檔案中新增依賴
發現還是一樣沒有導包 jar,一般情況下是可以匯入的。如果有朋友出現了我這樣的問題可以做一下操作
開啟控制檯 執行mvn命令
可以輸入以下命令
call mvn -f pom.xml dependency:copy-dependencies
mvn clean
mvn install
檢視哪些資源沒有下載下來,然後再根據情況手動下載即可。
然後我這把 maven不載入jar的問題解決了,你可以優雅的編碼了