简体   繁体   中英

Failed to execute goal org.codehaus.mojo:exec-maven-plugin when trying to execute a basic spring boot project

I created a Spring Boot Project using https://start.spring.io/ then made a Rest Controller with GET mapping to /students http

// This is the Controller.java file
package com.exampleqqq.demoqqq;

import java.util.ArrayList;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping(path = "/Students")
    public List<Student> getStudents() {

        Student obj1 = new Student(7, "Saman", "Colombo");
        Student obj2 = new Student(9, "Nimal", "Matara");

        List<Student> students = new ArrayList<>();
        students.add(obj1);
        students.add(obj2);
        return students;

    }
}

// This is the DemoqqqApplication.java file

package com.exampleqqq.demoqqq;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoqqqApplication {

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

}

// This is the student.java file

package com.exampleqqq.demoqqq;

/**
 *
 * @author Neva
 */
public class Student {

    private int id;
    private String name;
    private String address;

    public Student() {
        
    }
    
    public Student(int id, String name, String address) {
        this.id = id;
        this.name = name;
        this.address = address;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

}

// This is the pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.exampleqqq</groupId>
    <artifactId>demoqqq</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demoqqq</name>
    <description>Demo project for Spring Bootqqqqq</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

The Error is:

cd C:\Users\Neva\Documents\NetBeansProjects\demoqqq; "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_341" cmd /c ""C:\Users\Neva\Documents\NetBeansProjects\demoqqq\mvnw.cmd" -Dtest=**/*IT.java "-Dmaven.ext.class.path=C:\Program Files\NetBeans-14\netbeans\java\maven-nblib\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 test-compile surefire:test" Scanning for projects...

-----------------------< com.exampleqqq:demoqqq >----------------------- Building demoqqq 0.0.1-SNAPSHOT --------------------------------[ jar ]---------------------------------

--- maven-resources-plugin:3.2.0:resources (default-resources) @ demoqqq --- Using 'UTF-8' encoding to copy filtered resources. Using 'UTF-8' encoding to copy filtered properties files. Copying 1 resource Copying 0 resource

--- maven-compiler-plugin:3.10.1:compile (default-compile) @ demoqqq --- Nothing to compile - all classes are up to date

--- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demoqqq --- Using 'UTF-8' encoding to copy filtered resources. Using 'UTF-8' encoding to copy filtered properties files. skip non existing resourceDirectory C:\Users\Neva\Documents\NetBeansProjects\demoqqq\src\test\resources

--- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ demoqqq --- Nothing to compile - all classes are up to date

--- maven-surefire-plugin:2.22.2:test (default-cli) @ demoqqq --- ------------------------------------------------------------------------ BUILD FAILURE ------------------------------------------------------------------------ Total time: 0.872 s Finished at: 2022-08-05T14:09:08+05:30 ------------------------------------------------------------------------ Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-cli) on project demoqqq: No tests were executed. (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch. Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

your commandline contains:

-Dtest=**/*IT.java

so it looks for the test with that name and a test matching that pattern does not exists. So find out why your commandline has "-Dtest=**/*IT.java "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM