spring 如何在没有 pom 插件的情况下在 target 中启动创建 jar 文件

How spring boot create jar file in target without having plugin in pom

我正在阅读 spring-boot doc 他们说

To create an executable jar we need to add the spring-boot-maven-plugin to our pom.xml. Insert the following lines just below the dependencies section

<build>
  <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

以下是我的主 pom,其中包含其他模块

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
</parent>
<groupId>de.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<description>demo</description>

<properties>
    <java.version>1.6</java.version>
    <joda.version>2.5</joda.version>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- joda time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${joda.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>
<modules>
    <module>db</module>
    <module>web</module>
</modules>

以下是数据库

<parent>
    <groupId>de.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>db<artifactId>
<description>demo</description>

<dependencyManagement>
    <dependencies>
    <!-- spring data jpa -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>

    <!-- hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    </dependencies>
</dependencyManagement>

以下是网页

<parent>
    <groupId>de.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>

<dependencyManagement>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>db</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencyManagement>

我已经创建了多模块项目。我正在使用 spring 引导父项。在我的任何模块 pom 我没有上面的插件,但它仍然在目标文件夹中创建 jar 文件后我 运行 按照 web 模块上的命令作为基本目录

mvn clean install spring-boot:run

我缺少任何需要理解的东西。请发表评论。

Maven 使用 maven-jar-plugin to build a non executable jar file and spring-boot-maven-plugin 用于创建可执行 jar。

在你的情况下,即使你没有指定 spring-boot-maven-pluginmaven-jar-plugin 也会创建 jar 文件。

您可以在执行 mvn install 并查看构建日志时进行检查。