mastercool
mastercool

Reputation: 523

My Java code only works when ran from IDE, not terminal

I can run my Java program fine in the IDE but when I try this very first step in the command line:

  1. javac Main.java Test.java then I get a series of errors.

The errors are saying all of my imports do not exist

Main.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
Main.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Platform;
                          ^
Main.java:5: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                          ^
Main.java:6: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
                          ^
Main.java:7: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
                                 ^
Main.java:8: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.RemoteWebDriver;
                                 ^
Main.java:16: error: cannot find symbol
        DesiredCapabilities caps = new DesiredCapabilities();
        ^
  symbol:   class DesiredCapabilities
  location: class Main
Main.java:16: error: cannot find symbol
        DesiredCapabilities caps = new DesiredCapabilities();
                                       ^
  symbol:   class DesiredCapabilities
  location: class Main
Main.java:25: error: cannot find symbol
        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
        ^
  symbol:   class WebDriver
  location: class Main
Main.java:25: error: cannot find symbol
        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
                               ^
  symbol:   class RemoteWebDriver
  location: class Main
Main.java:27: error: cannot find symbol
        WebElement element = driver.findElement(By.name("q"));
        ^
  symbol:   class WebElement
  location: class Main
Main.java:27: error: cannot find symbol
        WebElement element = driver.findElement(By.name("q"));
                                                ^
  symbol:   variable By
  location: class Main
12 errors

What am i Doing wrong? How can I get my code to find these imports correctly?

EDIT: I have looked at the other answers and they are not working for me. All of my jar files are located here C:\Users\NROLL97\Documents\jars. Here is an example of what I've tried:

javac -cp "C:\Users\NROLL97\Documents\jars\*.jar:." Main.java

Upvotes: 0

Views: 443

Answers (2)

mastercool
mastercool

Reputation: 523

For anyone else who might come across this... Something like this is needed: java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml

.\target\classes is the path to the class files (not the .java files) and lib\* is the path to all of my jars in the lib folder.

Now all necessary dependencies will be found

Upvotes: 1

Mangesh
Mangesh

Reputation: 1

Okay First thing I wana recommend you is about how you are compiling your source code, well instead of writing each and every class name which you want to compile with any another class name just use * Example : javac *.java (hit enter button)

This command will compile all the java source file at a time instead of writting their names individually

Okay lets come to your problem Your compiler can't find selenium package or say .jar file which contains all the classes which are related to selenium classes

Download the .jar file which contains selenium related class in it and save it in the same location where you have saved your main.java and Test.java file

And then try to compile it

Upvotes: 0

Related Questions