繁体   English   中英

Spring 启动 maven 插件 - 如何构建可执行 jar 并包含运行它的脚本?

[英]Spring Boot maven plugin - how do I build an executable jar and include a script to run it?

I have a Spring Boot Java application that uses the spring boot starter parent and builds with the spring boot maven plugin. 我希望能够生成一个可执行的 jar 文件并包含一个可用于运行应用程序的 bash 脚本。 最终结果应该是带有 jar 文件和脚本的 zip 文件。 zip 也应包括所有依赖项。

我一直在尝试这样做,但在最终结果中包含脚本并没有任何运气。 实际上,我无法让它生成 zip 文件。 不知道我做错了什么。 spring 启动 maven 插件不能处理这种情况吗?

亲子关系:

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.1</version>
  </parent>

插入:

  <build>

    <finalName>archive-gitlab-project</finalName>

    <plugins>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <mainClass>a.b.c.MainClass</mainClass>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

我应该使用 spring 引导 maven 插件以外的东西吗?

 <configuration> <mainClass>/a/b/c/mainClass.class</mainClass> </configuration>

该配置错误,您需要使用 class 名称而不是文件名,即:

<configuration>
  <mainClass>a.b.c.mainClass</mainClass>
</configuration>

spring 启动 maven 插件不能处理这种情况吗?

实际上, spring-boot-maven-plugin可以做的更多: Unix 系统的完全可执行应用程序

暂无
暂无

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

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