Maven項目缺少Maven Dependencies解決方案總結

來源:互聯網
上載者:User

一、今天搭建了一個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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.