简体   繁体   English

spring-boot-maven-plugin 不会创建 fat jar

[英]spring-boot-maven-plugin doesn't create fat jar

I'm using spring-boot-maven-plugin to package my REST service.我正在使用spring-boot-maven-plugin来打包我的 REST 服务。 I'm building the jar using mvn clean install or mvn clean package .我正在使用mvn clean installmvn clean package构建 jar。 After I decompile the jar, I don't find any of the dependencies added (I was expecting it to be a fat jar with all dependencies)在我反编译 jar 之后,我没有找到任何添加的依赖项(我原以为它是一个包含所有依赖项的胖 jar)

在此处输入图片说明

 <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.5.9.RELEASE</version>
    <executions>
        <execution>
           <phase>install</phase>
           <goals>
              <goal>repackage</goal>
              <goal>build-info</goal>
           </goals>
        </execution>
    </executions>
    <configuration>
        <executable>true</executable>
        <finalName>myapp</finalName>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>

When I run the spring boot using java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" I'm getting ClassNotFoundException for many of the classes.当我使用java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal"运行 spring boot 时,我收到了许多类的 ClassNotFoundException 。 It's clear that artifact didn't build as expected.很明显,工件没有按预期构建。 However, if I start spring boot application using maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" I guess, it finds all the dependencies in target folder hence works fine.但是,如果我使用 maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal"启动 spring boot 应用程序,我猜它会找到目标文件夹中的所有依赖项,因此工作正常。 How can I fix the build issue so that I can start app using java -jar command.如何修复构建问题,以便我可以使用 java -jar 命令启动应用程序。

EDIT: It's multi-module maven project编辑:这是多模块 Maven 项目

it seems you are using a wrong command.看来您使用了错误的命令。 mvn clean package is maven command, you should use command 'repackage', it used for mvn clean package是 maven 命令,你应该使用命令 'repackage',它用于

Repackages existing JAR and WAR archives so that they can be executed from the command line using java -jar重新打包现有的 JAR 和 WAR 存档,以便可以使用 java -jar 从命令行执行它们

as it mentioned here https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html正如这里提到的https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html

Or probably it's plugin configuration issue.或者可能是插件配置问题。 Just checked: it works with spring-boot-maven-plugin-2.0.0.RELEASE刚刚检查:它适用于spring-boot-maven-plugin-2.0.0.RELEASE

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

Use this one用这个

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <mainClass>${start-class}</mainClass>
    <executable>true</executable>
    <fork>true</fork>
    <!-- Enable the line below to have remote debugging of your application on port 5005
         <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
     -->
  </configuration>
</plugin>

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

相关问题 spring-boot-maven-plugin 创建具有依赖项的 jar - spring-boot-maven-plugin create jar with dependencies Spring DevTools 未包含在 spring-boot-maven-plugin 打包的 fat jar 中 - Spring DevTools not included in the fat jar packaged with spring-boot-maven-plugin 运行 spring-boot-maven-plugin 配置的胖 JAR 时出现 ClassNotFoundException - ClassNotFoundException when running fat JAR configured by spring-boot-maven-plugin 龙目岛不适用于spring-boot-maven-plugin - Lombok doesn't work with spring-boot-maven-plugin spring 启动 maven 不 package ZEC407CCE6B649DAA8E320157EZjar6 文件 - spring boot maven doesn't package jsp files to “fat jar” spring-boot-maven-plugin创建的jar通过使用classpath运行 - spring-boot-maven-plugin created jar run by using classpath 无法在 spring-boot-maven-plugin 中分叉 - Unable to fork in spring-boot-maven-plugin spring-boot-maven-plugin:加载在哪里? - spring-boot-maven-plugin: where it is loaded? 多模块 Maven 和 Spring Boot 项目不会为辅助模块生成胖可执行 jar - Multi-module Maven and Spring Boot project doesn´t generate fat executable jar for secondary module 为什么 Java -cp 选项在使用 spring-boot-maven-plugin 时 -jar 不起作用? - Why is the Java -cp option not working when -jar does while using the spring-boot-maven-plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM