将Spring Boot应用程序导入另一个项目 [英] Import spring boot app into another project

查看:216
本文介绍了将Spring Boot应用程序导入另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试将spring boot可执行jar作为依赖项添加到另一个项目(测试框架)中.

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

但是一旦添加到pom并导入. Java导入无法正常工作.如果我在罐子里看,所有包装都以

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

还有一些与Spring Boot相关的软件包,清单等.

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

如果我将spring boot应用程序的构建切换为仅使用spring-boot-maven-plugin安装和部署常规jar,则不会

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

这将更改,并且一切正常.不幸的是,这对我们来说不是一个解决方案,因为在发布过程中,我们依赖可执行jar.

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.

我可以构建两个版本的jar并使用分类器来确定每个版本吗?

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

谢谢

推荐答案

事实证明,使用spring-boot-maven-plugin可以实现这种精确的情况.

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

春季启动应用的pom:

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>

使用spring boot jar的项目可以正常添加:

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>

如果要引用可执行jar,则为

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>

这篇关于将Spring Boot应用程序导入另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆