spring-boot-maven-plugin> = 1.4.0 jar结构更改 [英] spring-boot-maven-plugin >= 1.4.0 jar structure changes

查看:131
本文介绍了spring-boot-maven-plugin> = 1.4.0 jar结构更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个spring-boot项目,其中所有集成测试都在单独的模块中,该模块在integration-test阶段使用spring-boot-maven-plugin启动应用程序模块,并对它执行套件. 在将其升级到1.4.0.RELEASE之前,该结构运行良好.现在我得到一个ClassNotFoundException.

I have a spring-boot project where all integration tests are in separate module which starts the application module using spring-boot-maven-plugin during the integration-test phase and executes the suite against it. This construct worked fine until its been upgraded to 1.4.0.RELEASE. Now I get a ClassNotFoundException.

检查完"1.4.0" jar结构后,我发现它与"1.3.6"不同,并且所有软件包都不再位于顶层,而是位于BOOT-INF等文件夹中(请参见屏幕快照).如下所示),并且类加载器无法再找到"mainClass"中定义的包.

After I checked the "1.4.0" jar structure I figured out that its different than the "1.3.6" one and all the packages are no more on top level but in BOOT-INF etc. folders (see screen shots below) and the class loader can no more find the package defined in the "mainClass".

有人对修复它有想法吗,如果在新版本中可以使用此解决方案,那么是否有想法?

Does Someone have an idea about fixing it and if this solution is possible in the new version?

jar结构< 1.4.0 :

jar结构> = 1.4.0 :

ITest模块:

<!-- dependency to the app module -->
<dependency>
    <groupId>com.company.app</groupId>
    <artifactId>app-module</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
...
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring.boot.version}</version>
    <configuration>
        <mainClass>com.company.app.RunServer</mainClass>
    </configuration>
    <executions>
        <execution>
            <id>pre-integration-test</id>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>post-integration-test</id>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

应用程序模块:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

推荐答案

可以找到有关如何将Spring Boot应用程序用作依赖项的解决方案

A solution for how to use a Spring Boot application as a dependency can be found here.

基本上,在您的Maven构建中,添加以下内容:

Essentially, in your maven build, add this:

<build>
  <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <classifier>exec</classifier>
        </configuration>
    </plugin>
  </plugins>
</build>

这将使您的主jar工件(将在标准Maven构建中构建的工件)正常构建,因此您可以依靠它,而spring-boot-maven-plugin会将jar重新包装为第二个工件,这是一个具有exec分类器的可执行文件.

This will cause your primary jar artifact (the one which would be built in a standard maven build) to be structured normally, so you can depend on it, and the spring-boot-maven-plugin will repackage the jar into a second artifact, this one executable, with the exec classifier.

这篇关于spring-boot-maven-plugin&gt; = 1.4.0 jar结构更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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