Search code examples
javashellseleniumjenkinsjavac

Run Selenium Java Code on Jenkins master using shell


I'm trying to run a Java Selenium code on Jenkins using shell command. The Java file needs 3 .jar files in order to run. I tired, among other commands, Javac "*.jar" myfile.java which is not working.

I'm pulling the code form a repository and the master node is running RedHat 6. When I run javac myfile.java I get the follwoing error messgae:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
ClusterReloadAut.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
ClusterReloadAut.java:5: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                          ^
ClusterReloadAut.java:6: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
                                  ^
ClusterReloadAut.java:11: error: cannot access WebDriver
    static WebDriver driver = new FirefoxDriver();
           ^
  bad class file: ./WebDriver.class
    class file contains wrong class: org.openqa.selenium.WebDriver
    Please remove or make sure it appears in the correct subdirectory of the classpath.
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Solution

  • To compile your myfile.java into myfile.class (so you can run it with java command) you need to add a -cp path/to/selenium.jar to javac command. Like this:

    javac -cp path/to/selenium.jar myfile.java