Skip to content
Advertisement

Could not exec java with Spring+Maven exit code 1

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:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project gs-serving-web-content: Could not exec java: Application finished with exit code: 1 ->

I tried to add classpath, tried to run mvn install clean spring-boot:run, did a lot of other things that people suggested on stackoverflow in similar situations, spent on this more than 8 hours – no use.

Here is my main class Application.java:

JavaScript

Here is my GreeetingController.java class:

JavaScript

Here is my pom.xml file:

JavaScript

Here is my HTML template:

JavaScript

The structure of a project is

JavaScript

Advertisement

Answer

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:

JavaScript
  • Commented out the exclusions in the following part:

Commented out part:

JavaScript

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement