spring-boot-maven-plugin 不创建 fat jar
spring-boot-maven-plugin doesn't create fat jar
我正在使用 spring-boot-maven-plugin
打包我的 REST 服务。我正在使用 mvn clean install
或 mvn clean package
构建 jar。在我反编译 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>
当我 运行 spring 使用 java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal"
引导时,我得到许多 类 的 ClassNotFoundException。很明显,工件没有按预期构建。但是,如果我使用 maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal"
启动 spring 启动应用程序,我想,它会在目标文件夹中找到所有依赖项,因此工作正常。如何解决构建问题,以便我可以使用 java -jar 命令启动应用程序。
编辑:它是多模块 Maven 项目
您似乎使用了错误的命令。 mvn clean package
是 maven 命令,你应该使用命令 'repackage',它用于
Repackages existing JAR and WAR archives so that they can be executed
from the command line using 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>
用这个
<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>
我正在使用 spring-boot-maven-plugin
打包我的 REST 服务。我正在使用 mvn clean install
或 mvn clean package
构建 jar。在我反编译 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>
当我 运行 spring 使用 java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal"
引导时,我得到许多 类 的 ClassNotFoundException。很明显,工件没有按预期构建。但是,如果我使用 maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal"
启动 spring 启动应用程序,我想,它会在目标文件夹中找到所有依赖项,因此工作正常。如何解决构建问题,以便我可以使用 java -jar 命令启动应用程序。
编辑:它是多模块 Maven 项目
您似乎使用了错误的命令。 mvn clean package
是 maven 命令,你应该使用命令 'repackage',它用于
Repackages existing JAR and WAR archives so that they can be executed from the command line using 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>
用这个
<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>