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>

就可以了

  • 10
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值