Spring Boot Maven Build Failure

Hello guys, I seem to be stuck inside step number four of this exercise here:
Learn Spring | Codecademy

I have attempted it step by step multiple times but to no avail. I saw a couple of other users were also stuck on this exercise but unfortunately did not seem to receive any answers yet.
I receive multiple error messages when it comes time to run via the terminal. I am using Visual Studio Code for this exercise. I’ve tried Eclipse and STS3, but I can’t really figure out how to get a terminal to even show up on the latter.

Anyhow, the main error message I receive goes as follows:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:run (default-cli) on project mySpringDemo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:run failed: Unable to load the mojo 'run' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RunMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

I assume I need to change a certain version of something but am unsure what. Also, there are many lines of error codes after that which seem to all point to my .jar files (e.g. [ERROR] urls[50] = file:/C:/Users/binary/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar )

Here is my 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>3.0.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>mySpringDemo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>mySpringDemo</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-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>

This is my main .java file:

package com.example.mySpringDemo;

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

@SpringBootApplication
public class MySpringDemoApplication {

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

}

And this is the HelloController.java file:

package com.example.mySpringDemo;

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

@SpringBootApplication
public class MySpringDemoApplication {

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

}

Any help on this is much appreciated, as I really need to figure out Spring Boot for my course I’m in irl. If any more details are needed, please let me know. Thanks, and happy coding! :grinning:

Hello! Did you ever find a solution to your issue? Because I had a similar issue just now, and I was able to solve it.

For me, I had to update my JDK version to get everything working.

In VS Code, open the Explorer on the left side of the screen. At the bottom of the Explorer should be several expandable tabs, including one called JAVA PROJECTS. Click that one to expand it, then click the (…) symbol, aka ‘More Actions…’ Select ‘Configure Java Runtime’. This will open up a new tab. Click the ‘download’ link to open another tab, titled ‘Install New JDK’. My Spring project was configured for Java 17, so I checked that box and clicked the big Download button.

Run the installer. Make sure to include the option for the JAVA_HOME variable - I didn’t include it the first time and had to do it over again.

Once installed, run the command: ./mvnw spring-boot:run

This is what I did, and now things are working like the instructions said. I hope this is useful to someone!

2 Likes

Hey there! Sorry I haven’t responded to your post in a while.

I followed the instructions you provided and sure enough, no errors as well as success in finally getting “Hello World!” to appear on my browser.

Thank you, your help is much appreciated.

1 Like