You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vaadin 14 LTS+SpringBoot打包后java -jar运行提示无主清单属性

Vaadin 14 + Spring Boot 生产打包与启动异常问题排查

问题1:生产WAR包无法通过java -jar启动

  • 开发环境(IntelliJ)运行正常
  • 执行mvn clean package -Pproduction打包后,运行java -jar smcweb.war时抛出错误:no main manifest attribute, in smcweb.war
  • 其他纯Spring Boot API项目可正常用java -jar启动

问题2:启动控制台输出非Spring Boot标准Banner

  • 使用mvn spring-boot:run启动时,控制台输出自定义ASCII标识而非Spring Boot默认样式:
    [INFO] --- spring-boot-maven-plugin:2.5.4:run (default-cli) @ smcweb ---
    [INFO] Attaching agents: []
    Listening for transport dt_socket at address: 5230
                                     _                   _        
      __ _  _ __    ___ __  __  ___ | |__    __ _  _ __ | |_  ___ 
     / _` || '_ \  / _ \\ \/ / / __|| '_ \  / _` || '__|| __|/ __|
    | (_| || |_) ||  __/ >  < | (__ | | | || (_| || |   | |_ \__ \
     \__,_|| .__/  \___|/_/\_\ \___||_| |_| \__,_||_|    \__||___/
           |_|                                                    
    
  • 预期输出应为Spring Boot标准启动Banner:
    .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::                (v2.5.4)
    

备注

项目pom.xml中可能残留Payara Micro部署相关配置,已尝试常规Maven Manifest解决方案但未生效。


解决方案:修正Spring Boot Maven插件配置

问题根源在于Spring Boot插件配置缺失或被Payara相关配置干扰,需调整pom.xml中的插件配置:

  1. 移除Payara Micro相关插件:如果不再使用Payara部署,直接删除或注释掉对应的插件配置
  2. 正确配置Spring Boot Maven插件:确保包含repackage目标,并指定启动主类,同时恢复默认Banner
  3. 保留Vaadin生产打包插件:确保Vaadin前端资源正常编译打包

修正后的pom.xml核心配置片段

<build>
    <plugins>
        <!-- 移除或注释Payara Micro插件(如果不再使用) -->
        <!--
        <plugin>
            <groupId>fish.payara.maven.plugins</groupId>
            <artifactId>payara-micro-maven-plugin</artifactId>
            ...
        </plugin>
        -->

        <!-- Spring Boot Maven插件核心配置 -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.5.4</version> <!-- 与项目Spring Boot版本保持一致 -->
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal> <!-- 必须添加此目标,生成可执行WAR包 -->
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- 替换为你的Spring Boot启动类全路径 -->
                <mainClass>com.yourcompany.smcweb.SmcwebApplication</mainClass>
                <!-- 禁用自定义Banner,恢复Spring Boot默认样式 -->
                <bannerMode>console</bannerMode>
            </configuration>
        </plugin>

        <!-- Vaadin 14生产打包插件配置 -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>14.10.1</version> <!-- 匹配你的Vaadin 14 LTS版本 -->
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                        <goal>build-frontend</goal>
                    </goals>
                    <phase>compile</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

验证步骤

  1. 执行mvn clean package -Pproduction重新打包生产环境包
  2. 运行java -jar smcweb.war,检查是否正常启动,无no main manifest attribute错误
  3. 执行mvn spring-boot:run启动应用,确认控制台输出Spring Boot标准Banner

内容的提问来源于stack exchange,提问作者Diego Sebastián

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 06:05:19