2

I created my project at https://start.spring.io/
Several errors on the internet are similar but did not solve my problem.

when executing it I found an error return:

Failed to execute goal org.springframework.boot: spring-boot-maven-plugin: 2.4.1: run

Here are my POM and main file main

POM:

<?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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restfull-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restfull-webservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>

Class:

package net.javaguides.springboot;

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

@SpringBootApplication
public class SpringBootRestfullWebserviceApplication {

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

I'm new to Springboot, how do I fix it?

greybeard
  • 2,249
  • 8
  • 30
  • 66
  • How are you running maven? It looks like that project has a maven wrapper i.e. `mvnw.cmd` in the zip are you running `./mvnw.cmd clean install` or unix `./mvnw clean install` from the root where it was extracted – clD Dec 23 '20 at 16:04
  • yes maven! already ran the mvn command clean install qur also returns me an error – Natan Martins Nouzanadam Dec 25 '20 at 21:08
  • Have you tried adding the ` repository.spring.release Spring GA Repository https://repo.spring.io/plugins-release/ ` to the pom.xml. The lookup for `spring-boot-starter-parent` could be failing. – clD Dec 25 '20 at 22:18

3 Answers3

3

I've gotten your build to work, but I had to make some compromises.

I looked at the Spring documentation for what you are trying:

https://spring.io/guides/gs/rest-service/

Then I looked at the pom.xml for the example:

https://github.com/spring-guides/gs-rest-service/blob/master/complete/pom.xml

Despite the fact that the documentation says you can use Java 1.8 or higher, you need to use 1.8. If you go higher, you have to specify the property encoding in the plugin, and you can't do that because you are using the Spring Boot plugin rather than a plugin you can configure in the pom.xml for your project.

I also added a lower version of the maven-surefire-plugin than Spring Boot uses. With this version, you get the error [ERROR] There are test failures, but you are not running any tests.

I commented out the MySql and JPA dependencies, which won't work unless you have database connection settings.

<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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javaguides</groupId>
    <artifactId>spring-boot-restful-webservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-restful-webservice</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
 <!-- 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
 -->    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  
  <!--  
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <testFailureIgnore>true</testFailureIgnore>
                    <forkMode>once</forkMode>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>
geekTechnique
  • 850
  • 1
  • 11
  • 38
Dorothy
  • 31
  • 2
0

In my case i was running the jar file when i was activated maven install. The made it unable to delete and create a new jar as one was already running. After i quit running the jar file. I was able to build the project. sometimes reading error messages helps

mumbasa
  • 632
  • 7
  • 11
0

Try to read well the exception log in cli, after executing your "mvn spring-boot:run" command. It can be a due to

  • a connection with your DB, for example mysql not started

  • Or started but the DB name is not correct in your application.properties file e.g. java.sql.SQLSyntaxErrorException: Unknown database

  • Or even the password used of the db user is not correct in the application.properties file: e.g Caused by: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

so analyze first your logs before modifying java version, xml elements in the plugin ...

Normally this follwing generic pom.xml is enough to have maven running successfully your tomcat server (embedded in spring boot):

<?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 />
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

</project>
Youssef
  • 2,866
  • 1
  • 24
  • 20