0

I am trying to run a Java class with a bat file. I have created the bat file and, as I use selenium related libraries within the class, I added them in a folder and compiled with the help of it. The bat helps me compile, but I cannot run because of "Error: Could not find or load main class src\main\java\com\findyourbet\tennis\automation\CollectData.class Caused by: java.lang.ClassNotFoundException: src\main\java\com\findyourbet\tennis\automation\CollectData.class " I will post below my script and what I have tried.

My script is this:

set projectpath=C:\Users\Mihaaaa\IdeaProjects\tennis
 cd %projectpath%
 javac -cp lib/* 
 src\main\java\com\findyourbet\tennis\automation\CollectData.java

My lib is located in C:\Users\Mihaaaa\IdeaProjects\tennis and my class is in the path : C:\Users\Mihaaaa\IdeaProjects\tennis\src\main\java\com\findyourbet\tennis\automation. After running the bat, I tried the following commands, all with the class not found error:

java -classpath . src\main\java\com\findyourbet\tennis\automation\CollectData.class ( from the tennis folder)

java src\main\java\com\findyourbet\tennis\automation\CollectData.class ( from the tennis folder)

java -classpath . com.findyourbet.tennis.automation.CollectData ( from the automation folder and also from other folders as well )

java -classpath . CollectData.java ( from the folder where the class is, automation)

java -cp . com.findyourbet.tennis.automation.CollectData ( from automation folder)

java -cp . CollectData.class ( from automation folder)

None of these worked. Can anyone help me?

Maria1995
  • 439
  • 1
  • 5
  • 21
  • 1
    Possible duplicate of [What exactly is a class path in java?](https://stackoverflow.com/questions/22265463/what-exactly-is-a-class-path-in-java) –  Jul 02 '19 at 14:01

1 Answers1

0

Does your CollectData class contain a public static void main(String[] args) {} method?

Apart from that I would suggest you build a structure like:

  • src\main\java\com\findyourbet\tennis\automation\CollectData.class
  • lib\*.jar (put your dependencies there, i.e. the selenium jars)

Then running java -classpath lib src\main\java\com\findyourbet\tennis\automation\CollectData.class from the top level folder (containing src and lib) should work.

tim82
  • 92
  • 2