Looking for solution: NoClassDefFoundError

57 views
Skip to first unread message

Mike Frank

unread,
Oct 15, 2017, 3:20:36 PM10/15/17
to selenium-...@googlegroups.com, seleniu...@googlegroups.com

I am trying to run the script below on a Mac and I keep receiving a NoClassDefFoundError exception possibly due to the Chrome driver that I am using (I am assuming that is why I am getting an exception).


Details below:


Configuration

------------------

macOS Sierra v. 10.12.16

Selenium version: 3.6.0.

Chrome version: 2.33


SCRIPT

-----------

package tutorial6;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FindElementsBy {

    public static void main(String[] args) throws Exception {
        System.setProperty("webdriver.chrome.driver","/Users/mike.frank/Selenium/selenium-java-3.6.0/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.get("http://newtours.demoaut.com");                     

        List<WebElement> objLinks = driver.findElements(By.tagName("a"));

        for (WebElement objCurrentLink : objLinks) {  
                String strLinkText = objCurrentLink.getText(); 
                System.out.println(strLinkText);           
        }

        driver.navigate().refresh();
        driver.close();
        driver.quit(); 
    }
}


RESULT

----------

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at tutorial6.FindElementsBy.main(FindElementsBy.java:18)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 1 more

Krishnan Mahadevan

unread,
Oct 15, 2017, 11:33:21 PM10/15/17
to seleniu...@googlegroups.com, selenium-...@googlegroups.com

You are missing the guava libraries. Not sure how you are managing your dependencies.

If you are using Maven, you can follow the instructions here : http://www.seleniumhq.org/download/maven.jsp

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAG-WgUypqiARc0VbUQASkh1Ke8FynatOU1-2Vqcsekqb6e_vHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Mike Frank

unread,
Oct 18, 2017, 11:13:25 PM10/18/17
to seleniu...@googlegroups.com
Anybody have an answer to my question.  Do I really have to use Maven so that this error does not occur?  I am using Java 9. Is that an issue?

---------- Forwarded message ----------
From: Mike Frank <myke...@gmail.com>
Date: Tue, Oct 17, 2017 at 3:39 PM
Subject: Re: [selenium-developers] Re: [selenium-users] Looking for solution: NoClassDefFoundError
To: selenium-...@googlegroups.com


It would be great if someone could answer my question.

On Oct 16, 2017 9:37 AM, "Mike Frank" <myke...@gmail.com> wrote:
I am not using Maven. Should I be? Is there an alternative?

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-developers+unsubscribe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/51F2FC32-D723-4ECB-9A48-8920F2007AAC%40gmail.com.

Krishnan Mahadevan

unread,
Oct 19, 2017, 3:16:44 AM10/19/17
to seleniu...@googlegroups.com

Mike,

 

The whole point of using a build tool (Can be Maven or Gradle) is to ensure that when it comes to scenarios such as these, you don’t have to juggle around with things.

Is there any specific reason behind you not wanting to use a Build tool?

 

The root cause of the problem is very straight forward.

 

Your classpath is missing the guava libraries which selenium requires.

 

Build tools such as Maven/Gradle help you manage your classpath in an easier fashion.

 

And no, this issue doesn’t have anything to do with Java9, not atleast to the best of my knowledge.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-develo...@googlegroups.com.

 

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.


To post to this group, send email to seleniu...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages