NoClassDefFoundError in Java: com/google/common/base/Function
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.
Hope this helps.
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.
EDIT
After downloading the following libraries:
- Selenium: http://code.google.com/p/selenium/downloads/list
- Guava: http://code.google.com/p/guava-libraries/downloads/list
- Apache HttpComponents: http://hc.apache.org/downloads.cgi
- JSON jar: http://www.jarfinder.com/index.php/jars/versionInfo/21653
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 & Macjavac -cp .:lib/* Test.java java -cp .:lib/* Test# compile and run on Windowsjavac -cp .;lib/* Test.java java -cp .;lib/* Test
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>