繁体   English   中英

如何为无限启动(无限循环)的Spring Boot应用程序生成Jar文件?

[英]How to generate a Jar file for a Spring boot application which is running infinitely (Infinite loop)?

我知道如何构建具有所有依赖关系的应用程序的jar,但是这对我来说是一种情况,当我们构建jar(使用mvn包)时,它首先运行应用程序以检查一切是否正常(意思是:应用程序需要成功/正确停止)。 但就我而言,该应用程序不会停止,因为它正在运行无限循环且未创建任何jar。

有什么帮助吗? 很抱歉,如果这个问题重复。 我确实在这里搜索,找不到任何相对的答案。

Pom.xml

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
                <mainClass>${start-class}</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version><!--$NO-MVN-MAN-VER$ -->
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>path.to.mainclass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

提出问题已经有8个多月了,我认为OP可能已经找到了解决方案或已经提出。 为遇到同样问题的其他人写这个答案,并找到以下解决方案。

如问题中所述,当您运行mvn package / install时 ,它首先运行该应用程序以检查一切是否正常,然后创建该package / jar。

因此,一旦您确信该应用程序可以正常运行,请将其停止并重新运行mvn package / install ,但这一次跳过测试 这可以通过以下任何一种方式来完成。

  1. 如果您正在使用Spring Tool Suite:
    右键单击项目-> Run As-> Maven Build ...->在Main选项卡中, 选中“ Skip Tests”复选框 -> Apply-> Run
  2. 如果从命令行运行:
    mvn软件包-Dmaven.test.skip = true
  3. 另外,您可以在pom.xml文件中进行设置:
    <properties> <java.version>1.8</java.version> <maven.test.skip>true</maven.test.skip> </properties>
    并运行mvn包
  4. 如果您使用的是Surefire插件:
    mvn软件包-DskipTests

有关更多参考,请在下面找到源链接:

  1. https://www.mkyong.com/maven/how-to-skip-maven-unit-test/
  2. http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html
  3. https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/it-skip.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM