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?
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, ie 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.