Import spring boot app into another project

情到浓时终转凉″ 提交于 2019-12-21 04:32:20

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/40367589/import-spring-boot-app-into-another-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!