Eclipse中的项目没有Maven Dependencies 这个library的解决办法

本文介绍了解决Eclipse中Maven项目MavenDependencies库消失的问题,提供了两种有效的方法:使用UpdateProject功能更新.classpath文件,或直接修改.classpath文件,以确保项目的正确配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

版权声明:本文为优快云博主「lkforce」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/lkforce/article/details/81485629

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值