我正在使用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>当我使用java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal"运行spring boot时,我得到了许多类的ClassNotFoundException。很明显,工件没有像预期的那样构建。但是,如果我使用maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal"启动spring boot应用程序,它会发现目标文件夹中的所有依赖项,因此工作正常。如何修复构建问题,以便可以使用java -jar命令启动应用程序。
编辑:这是一个多模块的maven项目
发布于 2018-04-01 01:42:25
您似乎使用了错误的命令。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>发布于 2019-02-12 02:55:07
使用这个
<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>https://stackoverflow.com/questions/49590459
复制相似问题