Import spring boot app into another project

Michael W picture Michael W · Nov 1, 2016 · Viewed 9.3k times · Source

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

Answer

Michael W picture Michael W · Nov 1, 2016

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>