Reputation: 611
When I executing the following code:
public static void main(String[] args) {
try {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http:www.yahoo.com");
} catch (NoClassDefFoundError ex) {
System.out.println("error: " + ex.getStackTrace());
}
}
I'm facing the following error:
error:[Ljava.lang.StackTraceElement;@80f4cb
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
Could someone help me to find the solution or reason for this?
Upvotes: 61
Views: 224366
Reputation: 1221
I had the same problem, and finally I found that I forgot to add the selenium-server-standalone-version.jar. I had only added the client jar, selenium-java-version.jar.
Upvotes: 112
Reputation: 25050
I encountered the same error and after the investigation, I found that library selenium-api 2.41.0 requires guava 15.0 but it was overridden by an older version so I declared guava 15.0 as a direct dependency by adding following configuration in pom.xml:
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<type>jar</type>
<version>15.0</version>
</dependency>
Upvotes: 10
Reputation: 55
this is for chrome
System.setProperty("webdriver.chrome.driver","D:\\Testing_offical\\chromedriver.exe");
driver =new ChromeDriver();
this is for fire fox
System.setProperty("webdriver.gecko.driver",""D:\\Testing_offical\\geckodriver.exe"");
driver =new FirefoxDriver();
pattern :
System.setProperty("webdriver.gecko.driver","**Path of the gecko driver** ");
Note download gecko from here :- http://docs.seleniumhq.org/download/
Upvotes: 0
Reputation: 69
I got the same error, but it was resolved if you add the libraries of selenium (again if you haven't), if you are using INTELIJ
project>projectStructure>Module>+>add the selenium jars (both from lib folder and outside ones.).
Same needs to be done for other IDE's as well, like eclipse.
Upvotes: 2
Reputation: 157
I had the same issue. I found that I forgot to add selenium-2.53.0/selenium-java-2.53.0-srcs.jar file to my project's Reference library.
Upvotes: 1
Reputation: 51
I had the same problem, and finally I found that I forgot to add the selenium-server-standalone-version.jar. I had only added the client jar, selenium-java-version.jar.
Upvotes: 0
Reputation: 18594
I wanted to try a simple class outside IDE and stuff. So downloaded selenium zip from website and run the class like this:
java -cp selenium-2.50.1/*:selenium-2.50.1/libs/*:. my/package/MyClass <params>
I had the issue that I initially used lib
instead of libs
. I didn't need to add selenium standalone jar. This is Java 8 that understands wildcards in classpath. I think java 7 would also do.
Upvotes: 0
Reputation: 21
After you extract your "selenium-java-.zip" file you need to configure your build path from your IDE. Import all the jar files under "lib" folder and both selenium standalone server & Selenium java version jar files.
Upvotes: 0
Reputation: 11
Please include all the jar files of selenium stand-alone and lib folder, then this error will resolved
Upvotes: 1
Reputation: 3846
For me, in addition to selecting the jar - selenium-java-2.45.0.jar, I had to select all the jars in the "libs" folder under selenium root folder.
Upvotes: 3
Reputation: 11
I met the same problem and fail even after installing the 'selenium-server-standalone-version.jar', I think you need to install the guava and guava-gwt jar (https://code.google.com/p/guava-libraries/) as well. I added all of these jar, and finally it worked in my PC. Hope it works for others meeting this issue.
Upvotes: 1
Reputation: 1
When I caught the exception java.lang.NoClassDefFoundError: com/google/common/base/Function
it was caused by errors in Project Libraries.
Please check it in your project settings. For Intellij IDEA go to File - Project Structure and select Modules tab. All I needed to do to resolve this exception was re-adding the selenium library
Upvotes: 0
Reputation: 170148
A NoClassDefFoundError
is thrown when the JRE can't find a class. In your case, it can't find the class com.google.common.base.Function
, which you most probably did not add to your classpath.
After downloading the following libraries:
and unzipping them and putting all JAR files in a folder called lib
, the test class:
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
try{
FirefoxDriver driver = new FirefoxDriver();
driver.get("http:www.yahoo.com");
} catch(Exception e){
e.printStackTrace();
}
}
}
ran without any problems.
You can compile and run the class as follows:
# compile and run on Linux & Mac javac -cp .:lib/* Test.java java -cp .:lib/* Test # compile and run on Windows javac -cp .;lib/* Test.java java -cp .;lib/* Test
Upvotes: 24
Reputation: 36640
you don't have the "google-collections" library on your classpath.
There are a number of ways to add libraries to your classpath, so please provide more info regarding how you are executing your program.
if from the command line, you can add libraries to the classpath via
java -classpath path/lib.jar ...
Upvotes: 7
Reputation: 6054
It looks like you're trying to import some google code:
import com.google.common.base.Function;
And it's not finding it the class Function. Check to make sure all the required libraries are in your build path, and that you typed the package correctly.
Upvotes: 1