简体   繁体   English

如何解决无法找到或加载主类?

[英]How to solve Could not find or load main class?

I would like to build a java application. 我想建立一个Java应用程序。 System reported error message: 系统报告的错误消息:

Error: Could not find or load main class com.autoparts.autoeshop.Application

My controller: 我的控制器:

package com.autoparts.autoeshop;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class Application {

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

And I have written JAVA_HOME on system property. 而且我已经在系统属性上编写了JAVA_HOME。

Your environment is not completly correct as the JAVA_HOME should point to the installation directory ( jdk1.8.0_161 ) instead of bin and the PATH should include %JAVA_HOME%/bin . 您的环境不是完全正确的,因为JAVA_HOME应该指向安装目录( jdk1.8.0_161 )而不是bin ,并且PATH应该包含%JAVA_HOME%/bin

Your trial to compile with javac has been done from the wrong directory, you need to compile when you are in the java directory (including the relative path to the java file like com/autoparts/autoeshop/Application.java ). 您尝试使用javac进行编译是从错误的目录进行的,因此您在java目录中时需要进行编译(包括com/autoparts/autoeshop/Application.java等java文件的相对路径)。 Maybe your project has a build system prepared in the project directory ( autoeshop ) like Maven (look for a pom.xml ) or Gradle (find a build.gradle )? 也许您的项目在项目目录( autoeshop )中准备了一个生成系统,例如Maven (查找pom.xml )或Gradle (找到build.gradle )? If so, install the required build tool and run it, it will download all required dependencies and compile all the java files for you which is needed before you can run the application using the created jar file (typically found in a target (Maven) or build (Gradle) folder after the build tool ran. 如果是这样,请安装所需的构建工具并运行它,它将下载所有必需的依赖项并为您编译所有Java文件,然后才能使用创建的jar文件(通常在target (Maven)或build工具运行后,生成(Gradle)文件夹。

Anyway, if you struggle with this kind of problems you may consider to start with some basic Java or at least Spring Boot tutorials. 无论如何,如果您遇到这种问题,可以考虑从一些基本的Java或至少Spring Boot教程开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM