armjafar armjafar - 4 months ago 26
Bash Question

Run Selenium Java Code on Jenkins master using shell

Im trying to run a Java selenium code on Jenkins using shell command, java file needs 3 jar files in order to run

Im using Javac "*.jar" myfile.java

which is not working

I have tried few other command lines but it doesn't work

Im pulling the code form a repository and the master node is running RedHat 6

If I just use javac myfile.java

I get the follwoing error

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

Answer

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
Comments