Skip to content
Advertisement

How do you compile a java program from the command line while using selenium in the source code?

I am working on a final project for my Computer Science course. I built an program using the Selenium library to automate the process of creating a github repo and linking it to a local folder. I am only able to run the program inside of VS Code using their “Run” feature. I want to be able to run this from the Command Line in Windows, but I am not able to compile it since Java doesn’t recognize Selenium object types like WebDriver and WebElement. How would I compile it using this outside library?

Advertisement

Answer

It is strongly recommended to use Maven for java projects. It can fetch all the needed dependencies if you have added the maven dependency to the pom.xml file.

Otherwise download the Selenium jar file and use the following command to compile your code.

javac -cp .:jarfile1.jar:jarfile2.jar <MainClass>.java

and run the following to execute

java MainClass

2 People found this is helpful
Advertisement