24

I have three maven project one is pom package and other 2 are jar packaging here is the admin-aggreagator pom

<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>com.sounds.bvs</groupId>
    <artifactId>admin-aggregator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>


    <modules>
        <module>../admin-lib</module>
        <module>../admin-rest</module>
    </modules>


    <properties>
        <project.build.SourceEncoding>UTF-8</project.build.SourceEncoding>
        <spring-boot-version>2.0.4.RELEASE</spring-boot-version>
        <spring-version>2.0.4.RELEASE</spring-version>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <start-class>com.sounds.bvs.AdminRestApp</start-class>
    </properties>

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.sounds.bvs</groupId>
                <artifactId>admin-lib</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sounds.bvs</groupId>
                <artifactId>admin-rest</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                            <mainClass>${start-class}</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven.compiler.plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showDeprication>true</showDeprication>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

And the admin-rest pom.xml and its Main class i'm not getting as what i'm missing as the ctrl-click is navigating to respective project and type search is able to find the main class in admin-rest project ctrl+shift+T is also getting still it is showing same,

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

    <parent>
        <groupId>com.sounds.bvs</groupId>
        <artifactId>admin-aggregator</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>admin-rest</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.sounds.bvs</groupId>
            <artifactId>admin-lib</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jetty -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>


    </dependencies>
</project>

The Main Class AdminRestApp.java and i'm trying to run the admin-aggregator with

mvn clean spring-boot:run
mvnw.cmd clean spring-boot:run
./mvnw spring-boot:run 

but none are working

package com.sounds.bvs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AdminRestApp {

    public static void main(String[] args) {
        SpringApplication.run(AdminRestApp.class, args);
    }
}



and the exception i see class not found exception i tried all which were from similar topic none helped, the start-class tag is also place and hard code the full path com.sounds.bvs.AdminRestApp in mainClass still that also did not help,

i have tried changing spring boot version as well as maven compiler plugin version that also dint helped please help is need very badly.

earlier the package path was large com.sounds.bvs.admin.rest that time also same issue changed the package name also dint helped

please let me know what i'm missing thanks in advance.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] `enter code here`
[INFO] admin-aggregator
[INFO] admin-lib
[INFO] admin-rest
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building admin-aggregator 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ admin-aggregator ---
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) > test-compile @ admin-aggregator >>>
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) < test-compile @ admin-aggregator <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) @ admin-aggregator ---
[WARNING] 
java.lang.ClassNotFoundException: com.sounds.bvs.AdminRestApp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:491)
    at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] admin-aggregator ................................... FAILURE [ 42.358 s]
[INFO] admin-lib .......................................... SKIPPED
[INFO] admin-rest ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.280 s
[INFO] Finished at: 2018-08-10T00:43:37+05:30
[INFO] Final Memory: 17M/111M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) on project admin-aggregator: An exception occurred while running. com.sounds.bvs.AdminRestApp -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
3
  • I believe the two <module> elements in your parent project's pom.xml file have to be the names of the two child modules, not their relative path locations.
    – moilejter
    Aug 9, 2018 at 19:37
  • Have you installed the 2 dependencies locally? mvn clean install for both?
    – Daisy Day
    Aug 9, 2018 at 19:38
  • Yes done for both, the jar is available in .m2 but if i provide only names i will get bellow error [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Child module F:\STS Workspace\admin-aggregator\admin-lib of F:\STS Workspace\admin-aggregator\pom.xml does not exist @ [ERROR] Child module F:\STS Workspace\admin-aggregator\admin-rest of F:\STS Workspace\admin-aggregator\pom.xml does not exist @ then i google and change to relative path.
    – Vikram
    Aug 10, 2018 at 14:16

8 Answers 8

71

Adding a spring boot version solved my problem.

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

replace with your version of spring boot in Maven Tab ->plugins

1
  • I have the same problem, and this suggestion solved it. In addition, you might need to make sure the plugin version match your Spring boot version. So first check what is your current Spring Boot version and put the same version in the spring-boot-maven-plugin's version.
    – abmap
    Oct 2, 2022 at 14:23
29

it worked for me.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
2
  • It works for pom validation, but doesn't seems correct when you need to package your app into an executable jar (with specific configuration for spring boot repackage goal). In that case, this plugin should be added out of "pluginManagement", and version will have to be explicitly set. But in that case you can use ${project.parent.version} to avoid having to hard-code it.
    – StøcciD
    Nov 5, 2021 at 3:41
  • In my case, I saw this post and added the pluginManagement tag to wrap the plugins tag and the error message "Spring boot maven plugin class not found" stopped showing. Tks Mirrashad
    – Genivan
    Sep 4, 2022 at 1:36
11

Adding ${project.parent.version} to the dependency in pom.xml solved the problem for me.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>${project.parent.version}</version>
  <type>maven-plugin</type>
</dependency>

2
  • Please be a bit more specific and provide an example, if possible, of what you are suggesting. Thanks. Oct 6, 2021 at 7:10
  • 1
    I liked your post because of the ${project.parent.version}, allowing us to avoid to hard-code the version. But I would find it clearer to let it in build / plugin section, and not in dependencies section. (I tested it - Spring boot 2.5.5 - and it works, for pom validation and for packaging into executable jar)
    – StøcciD
    Nov 5, 2021 at 3:45
8

Only add the version.

<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-maven-plugin</artifactId> 
<version>${project.parent.version}</version> 

Exception Error

0
4

I read here https://docs.spring.io/spring-android/docs/2.0.0.M3/reference/html/maven.html. And followed the link: https://search.maven.org/ - typed in the search: spring-boot-maven-plugin..

And get my dependency. And it worked for me.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.3.4.RELEASE</version>
  <type>maven-plugin</type>
</dependency>
1

You have to execute the mvn spring-boot:run command from the module maven that contains the Spring Boot application (admin-rest), not from the parent module (admin-aggregator).
But you execute it from the parent module.

1
  • I also thought the same but it was given or defined in a ebook and asked to execute the mvn spring-boot:run on that so that it will start both. did i misunderstood something, if i should run on the spring boot application (admin-rest) what is the need of maintaining that admin-aggregator with only pom file in it and its maven packaging type is pom, and if i run on admin-rest it will run i tried in the beginning itself, still not getting what is the use of aggregator here? can you please suggest
    – Vikram
    Aug 10, 2018 at 14:15
0

I deleted .m2 folder and reinstall pom.xml file and the problem was solved.

0

You need to add the Spring Boot version like so:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.