0

I am trying to run a java file from selenium using cmd. Just adding libraries means that the java command (in command lines) does not work (javac works, the file is compiled). Does anyone know any hint?

package folder;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
public class fileJava{
  public static void main(String[] args){
    System.out.print("Hello World");
  }
}

enter image description here

1
  • 1
    Your command seems to be incorrect. Currently you're saying to java to run the file that is called folder.fileJava. Doublecheck if you do really have such file because it looks like a mix of folder and filename.
    – Alexey R.
    Commented Sep 24, 2018 at 17:52

3 Answers 3

1

You should run your code as

java folder/fileJava

Here is the test (I had to remove imports since I believe there are some not mentioned conditions specific for your environment)

C:\tmp>java folder/fileJava.class
Error: Could not find or load main class folder.fileJava.class

C:\tmp>java folder/fileJava
Hello World
C:\tmp>
0

@Alexy R is correct: Run it with a forward slash instead of a . operator as windows commandline may not be open to using . as folder notation. Additionally, if you still do get a classNotFoundException, it could be an issue with the classpath setting (May not have a '.' in the set of paths where a class file is searched for), in which case, you can confirm using the following:

C:...\Testy> java -classpath ./folder folder/fileJava

Hope this helps!

0

It's file for testing I really called them folder and filejava. In total the base file containing sql and selenium. I have simplified it as long as I found which piece of code causes a problem. Without imports is OK. The problem is when I adding the selenium libraries. I put "set classpath...." and it looks like there is no problem at the stage "javac...". File filejava.class appears. When I write "echo %classpath%" I see the libraries But when I want to run it I got: Error: Could not find or load main class Caused by java.lang.classNotFoundException. I have no idea where is the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.