63.1 包含该插件

想要使用Spring Boot Maven插件只需简单地在你的pom.xml的plugins部分包含相应的XML:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <!-- ... -->
  6. <build>
  7. <plugins>
  8. <plugin>
  9. <groupId>org.springframework.boot</groupId>
  10. <artifactId>spring-boot-maven-plugin</artifactId>
  11. <version>1.4.1.RELEASE</version>
  12. <executions>
  13. <execution>
  14. <goals>
  15. <goal>repackage</goal>
  16. </goals>
  17. </execution>
  18. </executions>
  19. </plugin>
  20. </plugins>
  21. </build>
  22. </project>

该配置会在Maven生命周期的package阶段重新打包一个jar或war。下面的示例展示在target目录下既有重新打包后的jar,也有原始的jar:

  1. $ mvn package
  2. $ ls target/*.jar
  3. target/myproject-1.0.0.jar target/myproject-1.0.0.jar.original

如果不包含像上面那样的<execution/>,你可以自己运行该插件(但只有在package目标也被使用的情况),例如:

  1. $ mvn package spring-boot:repackage
  2. $ ls target/*.jar
  3. target/myproject-1.0.0.jar target/myproject-1.0.0.jar.original

如果使用一个里程碑或快照版本,你还需要添加正确的pluginRepository元素:

  1. <pluginRepositories>
  2. <pluginRepository>
  3. <id>spring-snapshots</id>
  4. <url>http://repo.spring.io/snapshot</url>
  5. </pluginRepository>
  6. <pluginRepository>
  7. <id>spring-milestones</id>
  8. <url>http://repo.spring.io/milestone</url>
  9. </pluginRepository>
  10. </pluginRepositories>