Thymeleaf dependency causes "Error: Could not find or load main class" in Spring tool suite
Thymeleaf dependency causes "Error: Could not find or load main class" in Spring tool suite
我刚刚下载了 STS 并启动了一些 maven 项目并且它工作正常,但是当我开始使用 thymeleaf 时它不起作用。
我看到项目名称上有感叹号,我收到此错误 错误:找不到或无法加载主程序 class.
我尝试在 POM 中自己添加它的依赖项,我得到了那个错误,一旦我删除它们它就消失了!
我还尝试创建一个 "Spring Starter Project" 并选择要添加的依赖项 "Web and Thymeleaf",在创建项目后我立即在测试依赖项 的 POM 中看到语法错误传输失败 org.springframework.boot:spring-boot-starter-test:jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
当我删除它及其 class 时,我得到了上面相同的错误。
这是我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
尝试更新您的 Maven 存储库,请先尝试:
mvn dependency:purge-local-repository
Description:
When run on a project, remove the project dependencies from the local
repository, and optionally re-resolve them. Outside of a project,
remove the manually given dependencies.
然后尝试:
mvn dependency:copy-dependencies
Description:
Goal that copies the project dependencies from the repository to a
defined location.
在我看来,您的本地 Maven 存储库不包含 thymeleaf 依赖项。
删除失败的下载后问题已解决:
来自 CMD:
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
然后更新项目。
它重新下载了依赖项,它工作得很好。
我刚刚下载了 STS 并启动了一些 maven 项目并且它工作正常,但是当我开始使用 thymeleaf 时它不起作用。
我看到项目名称上有感叹号,我收到此错误 错误:找不到或无法加载主程序 class.
我尝试在 POM 中自己添加它的依赖项,我得到了那个错误,一旦我删除它们它就消失了!
我还尝试创建一个 "Spring Starter Project" 并选择要添加的依赖项 "Web and Thymeleaf",在创建项目后我立即在测试依赖项 的 POM 中看到语法错误传输失败 org.springframework.boot:spring-boot-starter-test:jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
当我删除它及其 class 时,我得到了上面相同的错误。
这是我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
尝试更新您的 Maven 存储库,请先尝试:
mvn dependency:purge-local-repository
Description:
When run on a project, remove the project dependencies from the local repository, and optionally re-resolve them. Outside of a project, remove the manually given dependencies.
然后尝试:
mvn dependency:copy-dependencies
Description:
Goal that copies the project dependencies from the repository to a defined location.
在我看来,您的本地 Maven 存储库不包含 thymeleaf 依赖项。
删除失败的下载后问题已解决:
来自 CMD:
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
然后更新项目。
它重新下载了依赖项,它工作得很好。