mavenintellij-ideaclasspathapache-crunch

Could not find or load main class while trying to run project from IntelliJ


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?


Solution

  • Configured and Tool classes are not added to the classpath since the scope of the dependencies in pom.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 from pom.xml, Import Changes to update the dependencies in the Maven project.