One Spring Boot project, deploy to both JAR or WAR

后端 未结 3 876
Happy的楠姐
Happy的楠姐 2020-11-30 06:04

Is there a way to have a single Spring Boot project be packagable into both JAR and WAR without changing the pom.xml or the application source?

I\'ve re

3条回答
  •  粉色の甜心
    2020-11-30 06:19

    I managed to do it by adding

    ${packaging.type}
    

    to the POM file and then setting different profiles for JAR and WAR:

      
        
          jar
          
            jar
          
        
        
          war
          
            war
          
          
            
              org.springframework.boot
              spring-boot-starter-tomcat
              provided
            
          
        
      
    

    Now mvn package -P war produces a WAR and mvn package -P jar produces a JAR.

    Another option is to create separate modules for JAR and WAR, but I didn't go that route.

提交回复
热议问题