Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import spring boot app into another project

So I am attempting to add a spring boot executable jar as a dependency in another project (Testing framework).

However once added to the pom and imported. Java imports don't work properly. If I look inside the jar all packages are prepended with:

BOOT-INF/classes.some.package.classname.class

There is also some spring boot related packages, MANIFEST etc etc.

Not if I switch the spring boot app's build to just install and deploy a regular jar using the spring-boot-maven-plugin

This changes and everything works fine. Unfortunately this is not a solution for us as we lean on the executable jar as part of our release process.

Can I build a deploy both versions of the jar and use a classifier to determine each?

Thanks

like image 512
Michael W Avatar asked Nov 01 '16 19:11

Michael W


1 Answers

Turns out this exact scenario can be achieved using the spring-boot-maven-plugin.

Spring boot app's pom:

  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.4.1.RELEASE</version>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin>

project using the spring boot jar can be added as normal:

    <dependency>
        <groupId>com.springboot</groupId>
        <artifactId>app</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>

OR if you want to reference the executible jar

    <dependency>
        <groupId>com.springboot</groupId>
        <artifactId>app</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <scope>test</scope>
        <classifier>exec</classifier>
    </dependency>
like image 177
Michael W Avatar answered Sep 19 '22 02:09

Michael W