简体   繁体   English

如何在 Intellij 的类路径上添加 class?

[英]How to add a class on classpath in Intellij?

I have the following project structure in Intellij:我在 Intellij 中有以下项目结构:

在此处输入图像描述

I am actually working with a maven project and all I wanna do is just run the project.我实际上正在使用maven项目,我想做的只是运行该项目。 Unfortunatelly I dont understand why but when I run the class called GenerateGraph it shows me the following error:不幸的是,我不明白为什么,但是当我运行名为GenerateGraph的 class 时,它向我显示以下错误:

Error: Could not find or load main class graph.GenerateGraph
Caused by: java.lang.ClassNotFoundException: graph.GenerateGraph

I dont understand why this happens- it is the first time I encounter something like that.我不明白为什么会发生这种情况——这是我第一次遇到这样的事情。 When I go on project structure I see the following:当我在project structure上 go 时,我看到以下内容:

在此处输入图像描述

Run configuration:运行配置: 在此处输入图像描述

seems like it doesnt even see that the graph package has a class inside.似乎它甚至没有看到图表 package 内部有一个 class 。 Could someone maybe help me understand what has happened?有人可以帮助我了解发生了什么吗? Is it because I renamed the package after importing the project?是不是因为我导入项目后重命名了package? Thank you very much in advance非常感谢您提前

Your project is not setup correctly.您的项目设置不正确。

You have reverseGraph marked as the sources root.您已将reverseGraph标记为源根。 In this case, src is the source folder.在这种情况下, src是源文件夹。

The typical Maven project structure is src/main/java for non-test source files and src/test/java for tests.典型的 Maven 项目结构是src/main/java用于非测试源文件和src/test/java用于测试。

What I'd recommend is modifying your folder structure:我建议修改您的文件夹结构:

  1. Remove reverseGraph移除reverseGraph
  2. Move src to the root of the project.src移动到项目的根目录。
  3. Add a src/main/java folder, and move your graph folder into that.添加一个src/main/java文件夹,然后将您的graph文件夹移动到该文件夹中。
  4. Reimport the Maven project in IntelliJ, and it should automatically flag the java folder in src/main as the sources root.在 IntelliJ 中重新导入 Maven 项目,它应该会自动将src/main中的java文件夹标记为源根目录。

Most likely the dependencies are not correctly set up - because you do not have this project opened as Maven project in IDE.很可能依赖项没有正确设置 - 因为您没有在 IDE 中将此项目作为 Maven 项目打开。 Please import this project as Maven project, see steps from Open an existing Maven project IntelliJ IDEA documentation section.请将此项目导入为 Maven 项目,请参阅打开现有 Maven 项目IntelliJ IDEA 文档部分中的步骤。

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

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