尝试从 IntelliJ 运行 项目时找不到或加载主 class
Could not find or load main class while trying to run project from IntelliJ
我已经下载了项目
git clone http://github.com/jwills/crunch-demo
然后将其作为 Maven 现有项目导入到 IntelliJ 中。现在我正在尝试 运行 main
函数,但失败并显示错误消息
Error: Could not find or load main class com.example.WordCount
这是什么以及如何解决?
更新
如果我从头开始创建新的 Hello World Maven 项目,那么它就可以工作。
更新 2
如果我做了 HelloWorld
class extends Configured implements Tool
,它也会停止工作:
public class HelloWorld extends Configured implements Tool {
public static void main(String[] args) {
System.out.println("Hello world");
}
@Override public int run(String[] strings) throws Exception {
return 0;
}
}
更新 3
我需要从 IntelliJ 的角度解释一下:它怎么会因为某些 class 扩展而失去在 class 路径中查找某些名称的能力?
出现这种情况可能是因为您的项目未正确打开。您将其导入 IntelliJ 是什么意思?请附上包含您打开的项目中的项目资源管理器的图像,我会尽力提供更多帮助。
Configured
和 Tool
class 没有添加到 class 路径中,因为 pom.xml
中的依赖范围被配置为 提供.
您不是 运行 提供这些依赖项的某些容器中的 class,而是直接来自 IDE,因此这些 classes 必须在class路径。
要解决此问题,请从 pom.xml
中删除所有 <scope>provided</scope>
标记,导入更改 以更新 Maven 项目中的依赖项。
我已经下载了项目
git clone http://github.com/jwills/crunch-demo
然后将其作为 Maven 现有项目导入到 IntelliJ 中。现在我正在尝试 运行 main
函数,但失败并显示错误消息
Error: Could not find or load main class com.example.WordCount
这是什么以及如何解决?
更新
如果我从头开始创建新的 Hello World Maven 项目,那么它就可以工作。
更新 2
如果我做了 HelloWorld
class extends Configured implements Tool
,它也会停止工作:
public class HelloWorld extends Configured implements Tool {
public static void main(String[] args) {
System.out.println("Hello world");
}
@Override public int run(String[] strings) throws Exception {
return 0;
}
}
更新 3
我需要从 IntelliJ 的角度解释一下:它怎么会因为某些 class 扩展而失去在 class 路径中查找某些名称的能力?
出现这种情况可能是因为您的项目未正确打开。您将其导入 IntelliJ 是什么意思?请附上包含您打开的项目中的项目资源管理器的图像,我会尽力提供更多帮助。
Configured
和 Tool
class 没有添加到 class 路径中,因为 pom.xml
中的依赖范围被配置为 提供.
您不是 运行 提供这些依赖项的某些容器中的 class,而是直接来自 IDE,因此这些 classes 必须在class路径。
要解决此问题,请从 pom.xml
中删除所有 <scope>provided</scope>
标记,导入更改 以更新 Maven 项目中的依赖项。