[英]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 install
或mvn 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.