简体   繁体   English

Pom 文件配置到 package 外部/自定义 jar 文件中的胖 spring 启动可执行文件 Z68904480F43A29DAC41

[英]Pom file configuration to package external/custom jar file in the fat spring boot executable jar file

My Requirement:我的要求:

I am trying to create a spring boot web project which has dependency on external/custom jar file.我正在尝试创建一个 spring 启动 web 项目,该项目依赖于外部/自定义 jar 文件。 I have added this dependency in the pom.xml file as below:我在 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>

I am not seeing any error during compile time.在编译期间我没有看到任何错误。 But when i am building the project and it is generating an executable fat jar file.但是当我构建项目并且它正在生成一个可执行的胖 jar 文件时。 this jar file has other dependencies but not the one which is added as "System scope" And run time it is throwing ClassNotFoundException.此 jar 文件具有其他依赖项,但不是作为“系统范围”添加的依赖项,并且运行时抛出 ClassNotFoundException。

Can anyone please tell me what configuration we have to add in pom.xml file so that system scope jar file will also added in the executable jar file. Can anyone please tell me what configuration we have to add in pom.xml file so that system scope jar file will also added in the executable jar file.

system scope is deprecated and act a lit bit like provided : the jar will be provided when you execute. system scope 已被弃用,并像provided的那样运行:jar 将在您执行时provided

Reading the documentation of the spring-boot-maven-plugin may help: it seems you can add <includeSystemScope>true</includeSystemScope> to the configuration of the plugin to includes said scope.阅读spring-boot-maven-plugin的文档可能会有所帮助:您似乎可以将<includeSystemScope>true</includeSystemScope>添加到插件的配置中以包含所述 scope。

Alternatively, you could try to first install the jar install:install-file goal:或者,您可以尝试先安装 jar install:install-file目标:

  • It would best done in a pom before your spring-boot project.最好在您的 spring-boot 项目之前在 pom 中完成。
  • If your build is in the same reactor, it would be best to have a provided dependency from spring-boot project to the project doing the install-file .如果您的构建在同一个反应器中,最好provided从 spring-boot 项目到执行install-file的项目的依赖项。

The answer from sanjeevRm could work, but you will have to ensure the proper layout: the install-file goal may do that for you by providing the localRepositoryPath . sanjeevRm的答案可能有效,但您必须确保布局正确: install-file 目标可以通过提供localRepositoryPath为您做到这一点。

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

You file must be placed in: ${project.basedir}/lib/repository/com/example/customjar/1.0/customjar-1.0.jar .您的文件必须放在: ${project.basedir}/lib/repository/com/example/customjar/1.0/customjar-1.0.jar中。

you can add following in pom and place artifact in this repository您可以在 pom 中添加以下内容并将工件放置在此存储库中

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

you can also check the import scope documentation .您还可以查看导入 scope 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM