I'm trying to create a project with Spring Boot using Intellij Ultimate (Java 1.8, Maven 3.5.4, Spring 2.0.4). It's my first Spring Boot project so I'm not sure if I'm using Maven correctly.
I've already tried the suggestions to edit the pom file and add the dependencies (spring-boot-starter-data-jpa, spring-boot-starter-web) from this link, but nothing worked.
package org.springframework.boot does not exist
I keep getting the following errors:
Information:java: JPS build failed to load optimized file manager for javac:
java.lang.NoClassDefFoundError: com/sun/tools/javac/util/DefaultFileManager
java.lang.NoClassDefFoundError: com/sun/tools/javac/file/JavacFileManager
Information:java: Errors occurred while compiling module 'demo'
Information:javac 8 was used to compile java sources
Information:2018-08-03, 5:14 PM - Compilation completed with 4 errors and 4 warnings in 6 s 430 ms
Warning:java: class org.jetbrains.jps.javac.ast.ExternalRefCollectorCompilerToolExtension : com/sun/source/util/TaskListener
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.
/Users/henryli/Desktop/demo/src/main/java/com/example/demo/DemoApplication.java
Error:(3, 32) java: package org.springframework.boot does not exist
Error:(4, 46) java: package org.springframework.boot.autoconfigure does not exist
Error:(6, 2) java: cannot find symbol
symbol: class SpringBootApplication
Error:(10, 9) java: cannot find symbol
symbol: variable SpringApplication
location: class com.example.demo.DemoApplication
Here is my pom.xml:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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>
Here is my code/ Java class:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
I used Spring Initializer to create this project and left all defaults, but it doesn't build.
mvn dependency:purge-local-repository
from the command line to remove all the dependencies. Thenmvn clean verify
to download and compile everything again. You have probably a few borked jars in your repository. – M. Deinum