想象:公司springboot项目要求测试环境时候打war包,然而平常开发为了方便喜欢打jar包。因为打包方式是通过pom.xml中packaging属性指定的,提交代码是把pom.xml也提交了,导致测试环境打的jar包,tomcat访问不起了。
    解决办法:
    第一步:在pom.xml添加自定义

    1. <profiles>
    2. <!-- 开发环境 -->
    3. <profile>
    4. <id>jar</id>
    5. <properties>
    6. <pom.package>jar</pom.package>
    7. </properties>
    8. <!--默认-->
    9. <activation>
    10. <activeByDefault>true</activeByDefault>
    11. </activation>
    12. </profile>
    13. <!-- 测试环境 -->
    14. <profile>
    15. <id>war</id>
    16. <properties>
    17. <pom.package>war</pom.package>
    18. </properties>
    19. </profile>
    20. </profiles>

    image.png
    第二步修:改破pom.xml packaging

    1. <packaging>${pom.package}</packaging>

    第三步:执行maven打包命令

    1. mvn clean package -P jar

    参考网址:
    https://blog.csdn.net/java_collect/article/details/83870215