Could not exec java with Spring+Maven exit code 1

后端 未结 5 1199
梦如初夏
梦如初夏 2021-01-18 03:07

I am new to Spring/Maven, and am following this tutorial: Serving Web Content with Spring MVC.

Everytime I run mvn spring-boot:run, I get this error:

相关标签:
5条回答
  • 2021-01-18 03:07

    I made the following changes to make mvn clean spring-boot:run work:

    • Move pom.xml to the root directory, which makes the directory hierarchy to be:

    Directory hierarchy:

    .
    ├── pom.xml
    └── src
        └── main
            ├── java
            │   └── hello
            │       ├── Application.java
            │       └── GreetingController.java
            └── resources
                └── templates
                    └── greeting.html
    
    • Commented out the extensions in the following part:

    Commented out part:

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- Exclusions to allow SpringBoot execute on HCP -->
            <!--<exclusions>-->
                <!--<exclusion>-->
                    <!--<groupId>org.springframework.boot</groupId>-->
                    <!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
                <!--</exclusion>-->
                <!--<exclusion>-->
                    <!--<groupId>org.apache.tomcat.embed</groupId>-->
                    <!--<artifactId>tomcat-embed-el</artifactId>-->
                <!--</exclusion>-->
                <!--<exclusion>-->
                    <!--<artifactId>logback-classic</artifactId>-->
                    <!--<groupId>ch.qos.logback</groupId>-->
                <!--</exclusion>-->
            <!--</exclusions>-->
        </dependency>
    

    It seems you meant to exclude those dependencies. mvn clean spring-boot:run will just exit successfully if the embed tomcat is excluded, but I think this is the correct behave because there's no container to deploy the application. Anyway, you can try it out and make changes according your requirements.

    0 讨论(0)
  • 2021-01-18 03:08

    I've same error as yours and finally I found it was cased by the wrong cooperation version between "spring-boot-starter-parent" and "spring-boot-autoconfigure", thereof making sure with same version. And also check their versions are the newest nor not.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
    
    0 讨论(0)
  • 2021-01-18 03:13

    In my case I just delete "tomcat-embed-el" dependency.

                    <exclusion>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-el</artifactId>
                    </exclusion>
    

    And it works.....

    0 讨论(0)
  • 2021-01-18 03:16

    In my case I just delete "devtools" dependency.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
    

    And it works!

    0 讨论(0)
  • 2021-01-18 03:22

    Sometimes the port might just be already in use, make sure you kill all java processes before running an application.

    0 讨论(0)
提交回复
热议问题