首页 文章

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

提问于
浏览
7

我正在使用 spring-boot-maven-plugin 打包我的REST服务 . 我正在使用 mvn clean installmvn clean package 构建jar . 在我反编译jar之后,我没有发现添加任何依赖项(我希望它是一个包含所有依赖项的胖jar)

enter image description here

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

当我使用 java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" 运行spring boot时,我明白了工件没有按预期构建 . 但是,如果我使用maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" 启动spring boot应用程序,我想,它会找到目标文件夹中的所有依赖项,因此工作正常 . 如何修复构建问题,以便我可以使用java -jar命令启动应用程序 .

编辑:这是多模块maven项目

2 回答

  • 4

    看来你使用了错误的命令 . mvn clean package 是maven命令,你应该使用命令'repackage',它用于

    重新打包现有的JAR和WAR归档,以便可以使用java -jar从命令行执行它们

    正如它在这里提到的https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html

    或者可能是插件配置问题 . 刚检查:它适用于 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>
    
  • 0

    使用这个

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

相关问题