Spring Boot with Agregator POM Packaging

Can I use the Spring Boots Maven plugin spring-boot:run command when the parent POM of the project uses the POM package because of its children?


I have a project with several maven modules with a "master" POM, which in it turns the child of the module of the parent Spring module. Something like that:

  <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>project</artifactId> <packaging>pom</packaging> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.0.BUILD-SNAPSHOT</version> <relativePath/> </parent> <modules> <module>module1</module> <module>module2</module> <module>module3</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <start-class>com.example.module1.Application</start-class> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> 

This is basically our β€œmain” POM, which every child uses as a parent. Now we want to execute the spring-boot:run command from the working directory where the "master" POM is located. The problem is that this throws a ClassNotFoundException , which is odd, since module1 (where this Application class is located) is included in the POM and is referred to as a module.

Using a single maven project module and <packaging>jar</packaging> , it compiles and runs the Application class, so Spring-Boot does not work.

What do I need to change to make this work, or is it just impossible to use the spring-boot-maven-plugin when working with multiple Maven modular projects?


Sidenote: my application class / module 1 has other modules as dependencies, so keep this in mind when answering the question. Any suggestions on how to improve this are greatly appreciated.

+7
java spring spring-boot maven
source share
2 answers

As I know, this is not possible because the plugin requires the launch of an executable jar.

Docs for spring-boot plugin The "run" target says:

Description

Run the executable archive application

Packaging pom will not create an executable. It will only generate pom.xml.

Try running mvn install and look at the artifact deployed in the local repository:

I just made for the module that I have with pom packaging:

 [INFO] Installing C:\projects\boot-parent\pom.xml to C:\Users\...\repository\no\boot-parent\0.0.1-SNAPSHOT\boot-parent-0.0.1-SNAPSHOT.pom 

As you can see, the artifact is boot-parent-0.0.1-SNAPSHOT.pom.


Try adding the plugin configuration to pom for module 1, which has an initial class (main class) and has packaging.

Edit for your comment:

Your comment suggests that you are having problems installing Maven on the client side. Check out this answer . And especially the answer given by @ChristianAchilli.

I use this problem by deleting the corresponding file to load the artifact directory in my local repo. The next time I run the maven command, the artifact download will start again. Therefore, I would say that this is a client-side configuration.

Again, hope this helps!

Thomas

0
source share

Make another module where only your application is inside. If you insert dependencies into your modules, you can start your normal mode using spring-boot: run or export as a jar.

Refer to your parent only as a container.

Hope this works for you

0
source share

All Articles