NoClassDefFoundError in Java: com / google / common / base / Function

When I execute 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 encountered the following error:

error: [Ljava.lang.StackTraceElement; @ 80f4cb

Exception in thread "main" java.lang.NoClassDefFoundError: com / google / common / base / Function


Can someone help me find a solution or a reason for this?

+54
java selenium-webdriver runtime-error
Feb 27 '11 at 18:18
source share
15 answers

I had the same problem and in the end I found that I forgot to add selenium-server-standalone-version.jar . I just added the client jar, selenium-java-version.jar .

Hope this helps.

+107
Mar 10 2018-11-11T00:
source share

A NoClassDefFoundError is thrown when the JRE cannot find the class. In your case, it cannot find the com.google.common.base.Function class, which you most likely did not add to your classpath.

EDIT

After loading the following libraries:

and unzip them and put all the JAR files in a folder called lib , a 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(); } } } 

works without 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
+22
Feb 27 '11 at 18:20
source share

I ran into the same error, and after investigating, I found that selenium-api 2.41.0 library requires guava 15.0, but it was overridden by an older version, so I declared guava 15.0 as a direct dependency by adding the following configuration to pom. XML:

 <dependency> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> <type>jar</type> <version>15.0</version> </dependency> 
+8
Apr 01 '14 at 8:26
source share

you do not have "google-collections" on your classpath .

There are a number of ways to add libraries to the classpath , so please provide more information on how you run your program.

if from the command line you can add libraries to the classpath via

java -classpath path/lib.jar ...

+7
Feb 27 '11 at 18:22
source share

For me, in addition to choosing jar-selenium-java-2.45.0.jar, I had to select all the banks in the "libs" folder in the folder with the root selenium.

+2
May 22 '15 at 5:06
source share

Please include all jar files in selenium standalone offline folder and lib folder, then this error will be resolved.

+2
Jul 02 '15 at 7:24
source share

It looks like you are trying to import google code:

 import com.google.common.base.Function; 

And it does not find the Function class. Make sure that all the required libraries are in your build path and that you entered the package correctly.

+1
Feb 27 '11 at 18:20
source share

I met the same problem and could not even after installing "selenium-server-standalone-version.jar", I think you need to install guava and guava-gwt jar ( https://code.google.com/p/guava- libraries / ). I added all these banks and finally worked on my PC. Hope this works for others who encounter this issue.

+1
Sep 15 '14 at 5:50
source share

I had the same problem. I found that I forgot to add the selenium-2.53.0 / selenium-java-2.53.0-srcs.jar file to my project help library.

+1
Aug 11 '16 at 12:05
source share

I have the same error, but it was decided if you add selenium libraries (again, if you didn’t), if you use INTELIJ

project> projectStructure> Module> +> add selenium banners (both from the lib folder and from the outside).

The same needs to be done for another IDE, for example, for eclipse.

+1
Jun 09 '17 at 19:37
source share

When I caught the java.lang.NoClassDefFoundError: com/google/common/base/Function exception, it was caused by errors in Project Libraries.

Please check it in the project settings. For Intellij IDEA, go to File - Project Structure and select the Modules tab. All I needed to do to eliminate this exception was re-adding the selenium library

0
May 12 '14 at
source share

After you extract the file "selenium-java-.zip", you need to configure your build path from your environment. Import all jar files into the "lib" folder and both standalone selenium server and Selenium java jar files.

0
Aug 23 '15 at 20:51
source share

I wanted to try a simple class outside of the IDE and stuff. So download selenium zip from the website and run the class as follows:

 java -cp selenium-2.50.1/*:selenium-2.50.1/libs/*:. my/package/MyClass <params> 

I had a problem due to which I originally used lib instead of libs . I should not have added an isolated can of selenium. This is Java 8, which understands wildcards in the classpath. I think java 7 will do as well.

0
Feb 01 '16 at 10:35
source share

I had the same problem, and finally I found that I forgot to add the server selenium-server-standalone-version.jar. I added only the client jar, selenium-java-version.jar.

0
Apr 08 '16 at 2:02
source share
 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/

0
Aug 04 '17 at 8:07 on
source share



All Articles