Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a simple JAR instead of an executable JAR with Spring-Boot

I have a problem with a Multi-Module Spring-Boot Application.

I have one Module that I use for Services, the core-Module. And one module for View-Related Classes, the web-Module. The are both in a parent-Module, where I add the dependencies, like the "spring-boot-starter" and that can be used by both modules.

Now to the problem:

I want to run the web-Module with the embedded Tomcat and have the core-Module as a dependency in the web-module.

In other Spring projects I would just include the maven-jar-plugin and create a jar of the core-Module.

The problem in this Spring-Boot project is that the maven-jar-plugin is already configured, in the "spring-boot-starter". And it needs a mainClass, which only the web-module has.

Small excerpt from the "spring-boot-starter"-POM

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${start-class}</mainClass>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

Is there a way to package the core-Module as a JAR without needing a "start-class" in that module?

like image 440
Johannes Esseling Avatar asked Jul 11 '16 17:07

Johannes Esseling


People also ask

What is the difference between jar and executable jar?

FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.

What is plain jar spring boot?

app-plain. jar is the archive produced by the jar task. This is a plain or standard jar file that contains only the module's classes and resources. You can learn a bit more about this in the documentation for Spring Boot's Gradle plugin.


2 Answers

You can just disable the spring-boot-maven plugin this way.

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
like image 133
SeB.Fr Avatar answered Sep 22 '22 12:09

SeB.Fr


To create simple jar update

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

To

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <classifier>exec</classifier>
        </configuration>
    </plugin>

For more details please visit below Spring URL:- https://docs.spring.io/spring-boot/docs/1.1.2.RELEASE/reference/html/howto-build.html

like image 31
Abhishek K Avatar answered Sep 20 '22 12:09

Abhishek K