java.lang.NoClassDefFoundError: org/apache/commons/exec/Executor

后端 未结 2 1466
天命终不由人
天命终不由人 2021-01-14 06:49

I am trying to execute the below code but getting error \"java.lang.NoClassDefFoundError: org/apache/commons/exec/Executor\" while running. I have added \"Common-Exec jar\"

相关标签:
2条回答
  • 2021-01-14 07:17

    Try adding this dependency, it worked for me

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-exec</artifactId>
        <version>1.3</version>
    </dependency>
    
    0 讨论(0)
  • 2021-01-14 07:25

    NoClassDefFoundError

    NoClassDefFoundError in Java occurs when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. For example, if we have resolved a method call from a class or accessing any static member of a class and that class is not available during run-time then JVM will throw NoClassDefFoundError.

    The error you are seeing is :

    Exception in thread "main" java.lang.NoClassDefFoundError: 
    org/apache/commons/exec/Executor
    

    This clearly indicates that Selenium is trying to resolve a particular class at runtime from org/apache/commons/exec/Executor which is not accessible/available.

    What went wrong :

    You have mentioned of adding Common-Exec jar but it seems that the related Class or Methods were resolved from one source during Compile Time which was not available during Run Time.

    This error occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK/Maven/Gradle and this situation happens when upgrading with new JAR files.

    Solution :

    Here are a few steps to solve NoClassDefFoundError :

    • If using Selenium JARs within a Java Project add only required External JARs within the Java Build Path and remove the unused/unwanted one.
    • Incase using a Build Tool e.g. Maven or Gradle, remove all the External JARs from the Java Build Path. Maven or Gradle will download and resolve all the required dependencies.
    • If using Selenium JARs, either use rather then using selenium-java-x.y.z Java Client use selenium-server-standalone-x.y.z.jar instead which bundles all the required dependencies together.
    • Incase using Maven, either use <artifactId>selenium-java</artifactId> or <artifactId>selenium-server</artifactId>. Avoid using both at the same time.
    • Remove the unwanted other <dependency> from pom.xml
    • Clean you Project Workspace within your IDE periodically only to build your project with required dependencies.
    • Use CCleaner tool to wipe away the OS chores periodically.
    • take a System Reboot.
    • Incase you are executing a Maven Project always do maven clean, maven install and then maven test
    0 讨论(0)
提交回复
热议问题