• no main manifest attribute, in ./XXX.jar,如何解决?


    启动springboot项目时,出现以下异常

    no main manifest attribute, in ./XXX.jar

    这是因为启动jar包时,未找到主类

    解决: 使用spring-boot-maven-plugin插件,在pom.xml配置以下内容

    1. org.springframework.boot
    2. spring-boot-maven-plugin
    3. 2.5.0
    4. repackage
    5. 主类全名

    需要注意一点,spring-boot-maven-plugin尽量选择高版本,(2.3.12.RELEASE)低版本可以打包成功,但是启动时依旧找不到主类。

    目前最新版本已经是2.7.2了,项目里面使用,要跟spring-boot-starter-web版本尽量保持一致,后续升级也好管理。

     在pom.xml配置好spring-boot-maven-plugin,先clean、后package即可完成打包

     如果不使用spring-boot-maven-plugin插件怎么打包?

    1、使用maven-shade-plugin,配置之后执行mvn clean package就OK了。

    1. <build>
    2. <plugins>
    3. <plugin>
    4. <artifactId>maven-compiler-pluginartifactId>
    5. <version>3.8.0version>
    6. <configuration>
    7. <source>1.8source>
    8. <target>1.8target>
    9. configuration>
    10. plugin>
    11. <plugin>
    12. <groupId>org.apache.maven.pluginsgroupId>
    13. <artifactId>maven-shade-pluginartifactId>
    14. <version>3.2.1version>
    15. <executions>
    16. <execution>
    17. <phase>packagephase>
    18. <goals>
    19. <goal>shadegoal>
    20. goals>
    21. <configuration>
    22. <transformers>
    23. <transformer
    24. implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
    25. <mainClass>com.cn.dl.main.ApplicationJobmainClass>
    26. transformer>
    27. <transformer
    28. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
    29. <resource>META-INF/spring.handlersresource>
    30. transformer>
    31. <transformer
    32. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
    33. <resource>META-INF/spring.schemasresource>
    34. transformer>
    35. transformers>
    36. configuration>
    37. execution>
    38. executions>
    39. plugin>
    40. plugins>
    41. build>

    2、使用maven-assembly-plugin插件,然后执行mvn clean assembly:assembly

    1. <build>
    2. <plugins>
    3. <plugin>
    4. <groupId>org.apache.maven.pluginsgroupId>
    5. <artifactId>maven-jar-pluginartifactId>
    6. <version>3.1.0version>
    7. plugin>
    8. <plugin>
    9. <artifactId>maven-assembly-pluginartifactId>
    10. <configuration>
    11. <descriptorRefs>
    12. <descriptorRef>jar-with-dependenciesdescriptorRef>
    13. descriptorRefs>
    14. <archive>
    15. <manifest>
    16. <mainClass>com.cn.dl.main.ApplicationJobmainClass>
    17. manifest>
    18. archive>
    19. configuration>
    20. plugin>
    21. plugins>
    22. build>

  • 相关阅读:
    java-php-python-公务用车管理智慧云服务监管平台计算机毕业设计
    Linux:firewalld防火墙-小环境实验(3)
    庖丁解牛:NIO核心概念与机制详解 07 _ 字符集
    【校招VIP】前端算法考点之智力分析
    mybatis-plus使用generator快速生成代码,并手动添加数据库命令
    Vue2 slot插槽学习笔记
    超强的纯 CSS 鼠标点击拖拽效果
    PyCharm中如何使用不同的虚拟环境
    数据结构---课后习题(第一章)
    数字政府建设要补上“+互联网”这一环
  • 原文地址:https://blog.csdn.net/qq_31289187/article/details/126309601