User 1
User 1

Reputation: 37

Could not find or load main class - Selenium webdriver java program

I have a selenium webdriver script that runs and works perfectly fine on eclipse. However, when I try to run it from the mac terminal, I keep getting errors.

I'm using this command to compile it on the terminal:

javac -cp ".:/Users/rkhalil/Downloads/selenium-2.48.2/selenium-java-2.48.2.jar:/Users/rkhalil/Desktop/selenium-2.48.2/selenium-java-2.48.2-srcs.jar:/Users/rkhalil/Desktop/selenium-2.48.2/libs/*" create_new_account.java

I get the following result:

Note: Some input files use or override a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

and when I try to run it using the following command:

java -cp ".:/Users/rkhalil/Downloads/selenium-2.48.2/selenium-java-2.48.2.jar:/Users/rkhalil/Desktop/selenium-2.48.2/selenium-java-2.48.2-srcs.jar:/Users/rkhalil/Desktop/selenium-2.48.2/libs/*" create_new_account

I get the following error:

Error: Could not find or load main class

Any help would be greatly appreciated.

Upvotes: 0

Views: 2317

Answers (1)

djangofan
djangofan

Reputation: 29669

That appears to be an easy answer. When you say -cp ".", apparently the class your trying to run is either uncompiled or simply not in the location expected. You can write a simple program to print out what is on the classpath:

ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
            System.out.println(url.getFile());
        }

But, to make it easier on yourself, I would suggest using Gradle to build and organize your project.

Upvotes: 1

Related Questions