如何更新我的 Eclipse 项目以包含“spring-boot-start-security-1.4.1.RELEASE.jar

How do I update my Eclipse project to include "spring-boot-start-security-1.4.1.RELEASE.jar

我构建了一个包含多个依赖项的项目。到目前为止,一切都很好。但是,我现在需要一个名为 "spring-boot-start-security-1.4.1.RELEASE.jar" 的新依赖项。我注意到所有 spring-boot-start-* 都位于 "Project and External Dependencies"。我在Maven Central找到了"spring-boot-start-security-1.4.1.RELEASE.jar"并下载了。我发现我无法将它加载到 "Project and External Dependencies"。我在我的项目中创建了一个 .lib 文件夹,并将 .jar 移动到该文件夹​​中。我右键单击该项目并继续属性 > Java 构建路径 > 添加外部 Jars... 然后单击我的 lib 文件夹中的 .jar。它已加载,但 eclipse 正在抱怨与 .jar 相关的几个导入无法解析。我可以将 "spring-boot-..." 添加到我的 Gradle 依赖项中,它将在命令行中使用 gradle build 正确构建。只是现在 Eclipse 正在抱怨几个无法解决的依赖项。有没有办法在我的项目中添加新的依赖项而不必重新开始?

您需要在 dependencies 标签下的 pom.xml 中添加此依赖项。添加 jar 不会将其添加到类路径中。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <version>1.4.2.RELEASE</version>
</dependency>

好的,我想出了如何使用 Gradle 将依赖项导入 Eclipse。需要明确的是,我想在创建项目后向我的 eclipse 项目添加一个新的 Spring 引导依赖项 -- "org.springframework.boot:spring-boot-starter-security:1.4.1.RELEASE"。当然,问题是 eclipse 没有安装正确的 jars。对这些 jar 的任何引用都会导致 eclipse 标记 import jar 语句 "cannot be resolved"。我在 gradle.build 依赖项中添加了“compile('org.springframework.boot:spring-boot-starter-security:1.4.1.RELEASE')。顺便说一句,我从 Maven Central 获得了正确的 Gradle 依赖项声明。如果我使用 Gradle 构建,则项目正确构建并安装了所有正确的 jars。但是,这是我的问题,Eclipse 没有 jars 并且继续咆哮说没有解决 jar - 非常烦人。构建有 jars 但 Eclipse 没有. 要将依赖项 jar 放入 Eclipse,请执行以下操作;

 1. Add the dependency into gradle.build shown below and save it.
      compile('org.springframework.boot:spring-boot-starter-security:1.4.1.RELEASE')

 2. Right Click on the Project > Gradle > Refresh Gradle Project

Gradle 然后使用 gradle.build 依赖项并将 jar 正确加载到项目的类路径中。没有更多的 Eclipse 吠叫!