[英]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 时,我看到以下内容:
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:我建议修改您的文件夹结构:
reverseGraph
reverseGraph
src
to the root of the project.src
移动到项目的根目录。src/main/java
folder, and move your graph
folder into that.src/main/java
文件夹,然后将您的graph
文件夹移动到该文件夹中。java
folder in src/main
as the sources root.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.