【问题标题】:Pom file configuration to package external/custom jar file in the fat spring boot executable jar filepom文件配置打包外部/自定义jar文件在fat spring boot可执行jar文件中
【发布时间】:2021-06-24 02:04:19
【问题描述】:

我的要求:

我正在尝试创建一个依赖于外部/自定义 jar 文件的 Spring Boot Web 项目。我在 pom.xml 文件中添加了这个依赖项,如下所示:

<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>customjar</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/customjar.jar</systemPath>
  </dependency>
</dependencies>

我在编译期间没有看到任何错误。但是当我正在构建项目并且它正在生成一个可执行的 fat jar 文件时。此 jar 文件具有其他依赖项,但没有添加为 "System scope" 并且运行时它抛出 ClassNotFoundException。

谁能告诉我我们必须在 pom.xml 文件中添加什么配置,以便系统范围 jar 文件也将添加到可执行 jar 文件中。

【问题讨论】:

    标签: java spring-boot maven


    【解决方案1】:

    阅读spring-boot-maven-plugin 的文档可能会有所帮助:您似乎可以将&lt;includeSystemScope&gt;true&lt;/includeSystemScope&gt; 添加到插件的配置中以包含所述范围。

    或者,您可以尝试先安装 jar install:install-file 目标:

    • 最好在你的 spring-boot 项目之前的 pom 中完成。
    • 如果您的构建在同一个反应器中,最好有一个从 spring-boot 项目到执行 install-file 的项目的 provided 依赖项。

    sanjeevRm 的答案可能有效,但您必须确保布局正确:安装文件目标可以通过提供 localRepositoryPath 为您做到这一点。

    <repositories>
        <repository>
            <id>local-project-repo</id>
            <url>file:${project.basedir}/lib/repository</url>
        </repository>
    </repositories>
    

    您的文件必须放在:${project.basedir}/lib/repository/com/example/customjar/1.0/customjar-1.0.jar

    【讨论】:

      【解决方案2】:

      您可以在 pom 中添加以下内容并将工件放置在此存储库中

      <repositories>
          <repository>
              <id>local-project-repo</id>
              <url>file:${basedir}/lib/repository</url>
          </repository>
      </repositories>
      

      您还可以检查导入范围 documentation.

      【讨论】:

        猜你喜欢
        • 2016-04-03
        • 2018-03-05
        • 2017-06-18
        • 2020-08-06
        • 2016-07-03
        • 2018-11-11
        • 1970-01-01
        • 1970-01-01
        • 2015-11-28
        相关资源
        最近更新 更多