首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-boot-maven-plugin不会创建fat jar

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

Stack Overflow用户
提问于 2018-04-01 01:22:31
回答 2查看 10.5K关注 0票数 10

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

代码语言:javascript
复制
 <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项目

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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一起工作

代码语言:javascript
复制
<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>
票数 10
EN

Stack Overflow用户

发布于 2019-02-12 02:55:07

使用这个

代码语言:javascript
复制
<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>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49590459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档