简体   繁体   中英

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. I have added this dependency in the pom.xml file as below:

<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. this jar file has other dependencies but not the one which is added as "System scope" And run time it is throwing 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.

system scope is deprecated and act a lit bit like provided : the jar will be provided when you execute.

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.

Alternatively, you could try to first install the jar install:install-file goal:

  • It would best done in a pom before your spring-boot project.
  • 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 .

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 .

<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 .

you can add following in pom and place artifact in this repository

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

you can also check the import scope documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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