1

I am reading spring-boot doc and there they said that

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>

Following are my main pom which includes other module

<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>

following is the db

<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>

following is web

<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>

I have created multi-module project. I am using spring boot parent. In any of my modules pom I do not have above plugin but still it create jar file in target folder after I run following command on web module as base directory

mvn clean install spring-boot:run

I am missing any thing to understand. Please do comment.

silly questions
  • 357
  • 6
  • 14

1 Answers1

4

Maven uses maven-jar-plugin to build a non executable jar file and spring-boot-maven-plugin is used to create an executable jar.

In you case even though you do not specify the spring-boot-maven-plugin, the maven-jar-plugin will create the jar file.

You can check this when you do a mvn install and see the build logs.

Omkar Puttagunta
  • 4,036
  • 3
  • 22
  • 35
  • Thank you for answer. that maven-jar-plugin is from spring-boot-parent pom? I could see the entry of spring-boot-maven-plugin in spring-boot-parent pom and I thought that is the reason behind that. Then why its there. It is confusing me.Please comment. – silly questions Jan 05 '16 at 12:07
  • 1
    In the parent pom, the `spring-boot-maven-plugin` is defined in the `pluginManagement` section. So your project will not use it unless you declare it as a `plugin` directly under `plugins` tag. For more info, Check - http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement – Omkar Puttagunta Jan 05 '16 at 13:01