I have downloaded project
git clone http://github.com/jwills/crunch-demo
then imported it into IntelliJ as Maven existing project. Now I am trying to run main
function, but failing with error message
Error: Could not find or load main class com.example.WordCount
What is it and how to fix?
UPDATE
If I create new Hello World Maven project from scratch, then it works.
UPDATE 2
If I make any HelloWorld
class extends Configured implements Tool
, it also stops working:
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;
}
}
UPDATE 3
I need explanation from the point of view of IntelliJ: how can it loose ability to find some names in classpath just because of some class extensions?
Configured
andTool
classes are not added to the classpath since the scope of the dependencies inpom.xml
is configured as provided.You are not running the class in some container that is providing these dependencies, but directly from the IDE, therefore these classes must be available in the classpath.
To fix the problem remove all the
<scope>provided</scope>
tags frompom.xml
, Import Changes to update the dependencies in the Maven project.