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

1k views Asked by At

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?

2

There are 2 answers

0
CrazyCoder On BEST ANSWER

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.

0
Macka On

This may be happening because your project is not correctly opened. What do you mean you imported it into the IntelliJ? Please attach an image containing the project explorer from your opened project and I will try to help more.