首页 > 解决方案 > 无法启动 Maven 服务 - 找不到类#

问题描述

好的...作为开发人员,我第一次不知道如何解决这个错误。

我在使用 Maven 命令和 Intellij 时遇到问题。

(重要的)

本地项目上的所有 maven 命令都不起作用并返回错误:

cannot find or load main class #, java.lang.ClassNotFoundException: #

错误消息中“#”的详细信息。

我的 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 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>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>garantia.safra</groupId>
    <artifactId>gateway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gateway</name>
    <description>description</description>

    <properties>
        <java.version>11</java.version>
        <start-class>garantia.safra.gateway.GatewayApplication</start-class>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <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>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwd</artifactId>
            <version>0.9.1</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-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>

我试图删除 .m2/repository 文件夹,但没有用。

我尝试“设置 > 构建、执行、部署 > 构建工具 > maven > 导入”并将导入设置为“项目 JDK”,但它没有用。(我使用的是 JDK 11,它以前可以工作)

我尝试通过 Intellij(远程和本地)更新 maven 存储库,现在远程存储库出现错误(找不到任何导入的包类)

我做的唯一一件事就是解决它一次,将项目重新创建为一个新项目并添加所有类和 pom.xml,但是当我添加我的配置文件时它又坏了。

我正在使用生产中的代理(.maven/jvm.config)

# -Dhttp.proxyHost=<proxy_host>
# -Dhttp.proxyPort=<proxy_port>
# -Dhttps.proxyHost=<proxy_host>
# -Dhttps.proxyPort=<proxy_port>

但是这些行都被注释了对吗?

和application.properties:

server.address=0.0.0.0

所以......这是一个非常烦人的问题,我缺乏想法。也许我会尝试再次重新创建项目并重新导入每个文件以查看哪个文件损坏,但如果有人之前遇到过这个问题并修复它......如何?

标签: javaspringmavenintellij-idea

解决方案


清空或删除.maven/jvm.config文件,直接加载并添加到命令行,不支持注释语法。


推荐阅读