1. 程式人生 > >Eclipse中的專案沒有Maven Dependencies 這個library的解決辦法

Eclipse中的專案沒有Maven Dependencies 這個library的解決辦法

Eclipse中的Maven專案應該有一個叫Maven Dependencies的library,如下:

也就是在Configure Build Path介面中的Maven Dependencies:

有時候這個庫會消失,這時候在Configure Build Path介面中點選Add Library按鈕是沒啥用的,我試了幾次都新增失敗了

正確的方法有兩種:

1,在專案上右鍵-->Maven--> Update Project

Update Project功能本身是用於當專案結構發生一些變化時更新專案,主要是更新.classpath檔案,讓Eclipse按照最新的.classpath檔案的內容處理專案。

2,直接改.classpath檔案

Maven Dependencies 這個library在.classpath檔案中是這麼標記的:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
	<attributes>
		<attribute name="maven.pomderived" value="true"/>
	</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
	<attributes>
		<attribute name="maven.pomderived" value="true"/>
	 </attributes>
</classpathentry>

把這段新增進去.classpath檔案,放在<classpath>標籤下,比如這樣:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="target/classes" path="src/main/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="output" path="target/classes"/>
</classpath>

就可以了