为SpringBoot应用程序构建了两个JAR

时间:2016-09-29 18:24:32

标签: java spring maven spring-boot

我正在使用spring boot 1.4.1并构建了一个非常简单的应用程序。当我使用下面的pom.xml时,我看到使用maven构建了两个JAR(abc.jar和abc-boot.jar)。我如何避免构建abc.jar,因为它只会浪费整体构建时间?

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>

    <groupId>abc</groupId>
    <artifactId>abc</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <!-- Need to avoid putting version in final jar's name -->
        <finalName>abc</finalName>
        <plugins>
            <plugin>
                <!-- Package as an executable jar -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>xyz.Application</mainClass>
                    <layout>ZIP</layout>
                    <classifier>boot</classifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:5)

你得到两个罐子,因为你已经用分类器配置了Spring Boot的Maven插件。这意味着它产生的脂肪罐与普通罐一起产生。

如果你想生产一个jar并且它是一个胖罐子,你应该从插件配置中删除<classifier>boot</classifier>

答案 1 :(得分:-1)

你得到两个工件,因为默认的程序集正在创建abc.jar,你添加的spring-boot-maven-plugin会产生另一个名为abc-boot.jar的jar。
或者,您可以摆脱spring-boot-maven插件,仍然可以生成一个可执行jar。这可以通过配置maven程序集插件来完成,如下例所示。

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          [...]
          <archive>
            <manifest>
              <mainClass>org.sample.App</mainClass>    //specify your spring-boot main class here.
            </manifest>
          </archive>
        </configuration>
        [...]
      </plugin>
      [...]
</project>