一、今天搭建了一個maven項目,在pom.xml檔案引入依賴後,發現項目結構中沒有Maven Dependencies檔案(下圖),但是在java Build Path中又可以找到Maven Dependencies檔案(如下圖),
但是,pom.xml檔案中添加的依賴jar包也不會自動下載到項目中,update Project也是一樣,於是是網上尋找了很多方法,嘗試後都發現沒有用,最終,查看自己的pom.xml檔案,發現是在依賴前面寫了<dependencyManagement>這個標籤(下圖),查資料後發覺這個標籤的作用只是聲明依賴,並不實現依賴的引入,因此,沒有jar包的引入,maven項目就不會顯示Maven Dependencies檔案。去掉這個標籤後,問題解決,maven Dependencies檔案出現在maven項目中。
二、網上其他解決Maven Dependencies檔案缺失的方法:
第1種:Maven支援沒有開啟:這種情況一般是Eclipse內建的Maven,或者自己裝的Maven並沒有開啟服務。
解決方案:右鍵Maven項目-->Maven-->Enable Dependency Management
(可能有一些maven版本沒有Enable Dependency Management這個選項)
第2種:classpath檔案問題或者.project檔案問題:
解決方案:
(1)在.classpath檔案中添加如下代碼
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"><attributes><attribute name="maven.pomderived" value="true"/><attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/></attributes></classpathentry>
(2)在.project檔案的<natures>中添加紅色字型部分:
<natures><nature>org.eclipse.jem.workbench.JavaEMFNature</nature><nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature><nature>org.eclipse.jdt.core.javanature</nature><nature>org.eclipse.m2e.core.maven2Nature</nature><nature>org.eclipse.wst.common.project.facet.core.nature</nature><nature>org.eclipse.wst.jsdt.core.jsNature</nature></natures>
第3種:項目-->properties-->Deployment Assembly-->Add-->java build path Entries-->Maven Dependencies--Finish
第4種:項目為非maven項目(情況較少)
解決方案:右鍵項目-->configure-->Convert to Maven Project