如何在Spring Boot中创建一个单一的可执行的WAR文件
如何在Spring Boot中创建一个单一的可执行的WAR文件
我们正在使用Spring Boot开发Spring Cloud项目。我们的目标是创建一个可执行的war文件,可以通过java -jar命令运行。我在Stack Overflow上查找了一些帖子,并成功生成了可执行的war文件,方法如下:\n1)在pom.xml文件中添加\"boot\"分类标签。\n2)在spring-boot-maven-plugin插件的执行阶段添加Repackage目标。\n现在,使用这种方法,我得到了两个war文件:\n一个war文件不可执行,只能部署;\n另一个带有boot分类标签的war文件符合我的要求。\n有没有办法只生成可执行的war文件呢?\n我附上了pom.xml文件以供参考。
如何在Spring Boot中创建一个单个可执行的war包
最初的问题是在目标文件夹中得到了两个war文件:Root.war和discovery-service-boot.war。经过查找发现,问题出在maven-war-plugin的配置上。当移除了warName和outputDirectory的xml标签后,成功得到了可执行的war包。
以下是最终的pom.xml文件,可以帮助其他遇到类似问题的人:
4.0.0 discovery-service 1.0.0-SNAPSHOT war Discovery microservice to provide a service registry using Spring Cloud and Netflix Eureka for cloud native microservices. 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugin 1.2.3.RELEASE repackage org.apache.maven.plugins maven-war-plugin 2.6 false org.springframework.cloud spring-cloud-starter-eureka-server org.springframework.cloud spring-cloud-dependencies Brixton.SR1 pom import org.springframework.cloud spring-cloud-starter-parent Brixton.SR1 pom import
关于Spring Boot Maven插件中的repackage目标以及使用classifier的后果的一些信息:
[docs.spring.io/spring-boot/docs/current/maven-plugin/examples/repackage-classifier.html](http://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/repackage-classifier.html)