我们正在使用 Spring Boot 开发 Spring Cloud 项目。我们的目标是创建一个可以使用 java -jar 运行的可执行 war。
我关注了 SO 上的几篇文章,并能够通过 1) 在 .
2) 在 spring-boot-maven-plugin 的执行阶段添加 Repackage 目标
现在通过这种方法我得到了两个战争文件:
一场不可执行但可部署的战争
以及另一场适合我的要求的引导分类器战争
有没有办法只生成可执行的战争?
我附上 pom.xml 以便于参考
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<artifactId>discovery-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>
Discovery microservice to provide a service registry using Spring Cloud
and Netflix Eureka for cloud native microservices.
</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.3.RELEASE</version>
**<configuration>
<classifier>boot</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>**
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>target</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
参考:一个 Spring Boot 项目,部署到 JAR 或 WAR https://stackoverflow.com/questions/23868580/one-spring-boot-project-deploy-to-both-jar-or-war
运行 java -jar 时无法加载主类清单属性 https://stackoverflow.com/questions/19620342/failed-to-load-main-class-manifest-attribute-while-running-java-jar
感谢 Stephane 建议删除分类器并建议使用 starter.io。
我最初的问题是我在目标中收到两个战争文件:
- Root.war 和其他
- 发现-服务-boot.war
我猜,问题出在 maven-war-plugin 配置中。删除 warName 和 outputDirectory 的 xml 标签后,我得到了可执行的 war。
我发布了最终的 pom.xml 以使其他面临类似情况的人受益:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>discovery-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>
Discovery microservice to provide a service registry using Spring Cloud
and Netflix Eureka for cloud native microservices.
</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.3.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)