Problem: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project EndtoEndProj: Compilation failure: Compilation failure
[ERROR] /C:/user/Study/ProjectName/src/main/java/resources/ExtentReporterNG.java:[9,18] package org.testng does not existSolution: If the scope of testng depency in pom .xml file is defined as test as below:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
1. change the version to : <version>7.0.0</version> and try.
2. With this scope , If we run mvn compile , throwing errors.
So update the scope as: <scope>compile</scope> and try.
Problem: [ERROR] : Unable to initialize main class SeleniumTest
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Solution: 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
.
What went wrong :
From all the above mentioned points it’s clear that the related Class or Methods were resolved from one source Compile Time which was not available during Run Time.
This situation occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK / Maven / Gradle.
Here are a few steps to solve NoClassDefFoundError :
- While 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 within a Java Project add only required External JARs within the Java Build Path and remove the unused one.
- While 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>
frompom.xml
- Clean you Project Workspac within your IDE periodically only to build your project with required dependencies.
- Use CCleane tool to wipe away the OS chores periodically.
- While you execute a Maven Project always do
maven clean
,maven install
and thenmaven test
.
Source: https://stackoverflow.com/questions/47823506/exception-in-thread-main-java-lang-noclassdeffounderror-org-openqa-selenium-w
Problem: Maven Compilation error : “Compiling for Java version ‘1.7’ is no longer supported. Minimal supported version is ‘1.8’”
Solution:
Option 1: Update Maven Compiler Plugin (Recommended).
Add or update the Maven compiler plugin in your pom.xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Option 2: Use Modern Java Version (Better Choice)
For better compatibility with latest Selenium versions, use Java 11 or higher:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
Option 3: Check Your IDE Configuration
For Eclipse:
- Right-click project → Properties
- Java Build Path → Libraries
- Remove old JRE System Library
- Add Library → JRE System Library → Choose JRE 1.8 or higher
For IntelliJ IDEA:
- File → Project Structure
- Project Settings → Project → Project SDK: Choose 1.8 or higher
- Modules → Sources → Language Level: Choose 8 or higher