Good afternoon, there is a code written in libraries org.openqa.selenium. It gives an error java.lang.ClassNotFoundException:

code:

import org.openqa.selenium.WebDriver; import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.phantomjs.PhantomJSDriverService; import org.openqa.selenium.remote.DesiredCapabilities; public class seofast { public static void main(String[] args){ DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true); caps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, "phantomjs-2.1.1-windows\\bin\\phantomjs.exe"); WebDriver driver = new PhantomJSDriver(); driver.get( "http://www.seo-fast.ru" );} } 

here is the error:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at seofast.main(seofast.java:10) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more 

    2 answers 2

    Your application’s classpath does not have the required JAR file containing the com.google.common.base.Function class

      Despite the fact that the upper answer is already marked true, I can see that this does not always happen. For example, if this class inherits from java.util.Function - an analogue of lambda in 8 java, then java will still say that such a class com / google / common / base / Function does not exist.