简体   繁体   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. I have a Spring Boot Java application that uses the spring boot starter parent and builds with the spring boot maven plugin. I would like to be able to produce an executable jar file and include a bash script that can be used to run the application.我希望能够生成一个可执行的 jar 文件并包含一个可用于运行应用程序的 bash 脚本。 The end result should be a zip file with the jar file and script.最终结果应该是带有 jar 文件和脚本的 zip 文件。 The zip should include all dependencies as well. zip 也应包括所有依赖项。

I've been trying to do this, but have not had any luck with including a script in the end result.我一直在尝试这样做,但在最终结果中包含脚本并没有任何运气。 Actually, I haven't been able to get it to produce a zip file.实际上,我无法让它生成 zip 文件。 Not sure what I'm doing wrong.不知道我做错了什么。 Does the spring boot maven plugin not handle this kind of scenario? spring 启动 maven 插件不能处理这种情况吗?

Parentage:亲子关系:

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

Plugin:插入:

  <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>

Should I be using something other than the spring boot maven plugin?我应该使用 spring 引导 maven 插件以外的东西吗?

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

that configuration is wrong, you need to use class name instead of file name, ie:该配置错误,您需要使用 class 名称而不是文件名,即:

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

Does the spring boot maven plugin not handle this kind of scenario? spring 启动 maven 插件不能处理这种情况吗?

Actually, spring-boot-maven-plugin can do even more: fully executable applications for Unix systems实际上, spring-boot-maven-plugin可以做的更多: Unix 系统的完全可执行应用程序

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

相关问题 Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? - Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? 我可以通过“Spring Boot Maven Plugin”制作带有“build-info”的可执行 jar 吗? - Can I make an executable jar with “build-info” by “Spring Boot Maven Plugin”? 如何在生产环境中运行 spring boot 可执行 jar? - How do I run a spring boot executable jar in a Production environment? 如何使用Maven插件正确构建Spring Boot far jar? - How to properly build a Spring Boot far jar using maven plugin? Spring Boot + Gradle:如何构建可执行jar - Spring Boot + Gradle: how to build executable jar Maven和Netbeans:我如何构建项目并获得可执行jar? - Maven and Netbeans: how do I build project and get executable jar? Maven:如何将我的外部 jar 包含到构建可执行 jar 中 - Maven: How to include my external jar into build executable jar Maven:如何使用故障安全插件在jar中运行/包含类? - Maven: How can I run/include a class in a jar with the failsafe plugin? 如何使用maven-jar-plugin和groovy构建可执行jar? - How to build executable jar using maven-jar-plugin and groovy? 如何使用 Spring Boot Gradle Plugin 2.1.* 构建不可执行的 jar(库) - How to build not executable jar (library) with Spring Boot Gradle Plugin 2.1.*
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM