Spring引导:在 Spring 引导项目中添加第 3 方 jar

SpringBoot: Adding 3rd Party jars in a Spring Boot Project

我已经设置了 MAVEN 路径和变量。我能够在 Eclipse 中 运行 一个示例 SpringBoot 项目,但我想要的是我有一个自定义 jar 并且我在我的 Spring 引导中使用该 jar 中的 类项目。当我包含此自定义 jar 并构建 Spring 启动应用程序时,出现以下错误

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (D:......\SpringBootDemo\target).

Please verify you invoked Maven from the correct directory. -> [Help 1]

org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a project to execute but there is no POM in this directory (D:......\SpringBootDemo\target).

Please verify you invoked Maven from the correct directory.

我的POM.xml如下:

<groupId>com.demo</groupId>
<artifactId>SpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>SpringBootDemo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我错过了什么吗?

任何帮助将不胜感激。

谢谢

有时您需要将第 3 方 JAR 放入您的本地存储库中以便在您的构建中使用,因为它们不存在于任何 public 存储库中,例如 Maven Central. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven. To make this easier, and less error prone, we have provide a goal in the maven-install-plugin 这应该使这相对无痛。要在本地存储库中安装 JAR,请使用以下命令:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

maven-install-plugin 的 2.5 版本变得更好。如果 JAR 是由 Apache Maven 构建的,它将在 META-INF 目录的子文件夹中包含一个 pom.xml,默认情况下将读取该目录。在这种情况下,您需要做的就是:

mvn install:install-file -Dfile=<path-to-file>

来自 Maven Guide to installing 3rd party JARs.