Maven Errors


Problem: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Solution: Follow the solution 2 or 3 as per this link ->


Problem: Maven build Compilation error ‘Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven’ 

OR: After adding Extentreport file, Maven build is not working.

Solution: Follow either one or both solutions. 

1.Need to configuration maven-compiler-plugin in Pom.Xml file as below, save and run again. To know more, click here ->

<project>
<properties>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</Project>


2.Follow the below instruction if the issue is still happening:

-Open pom.xml file.
-Go to “Dependencies” tab.
-Select “testng” package and click on “Properties…”
-On opened screen change “Scope” option to “compile” and click “OK” to save it.
-Try to build your project again with “compile test” goals


Problem: The JAVA_HOME environment variable is not defined correctly

This environment variable is needed to run this program

NB: JAVA_HOME should point to a JDK not a JRE

Solution: Follow this Link->


Problem: NoGoalSpecifiedException

Solution: Define a default goal in your POM as shown below

<project>
  ...
  <build>
    <defaultGoal>install</defaultGoal>
    ...
  </build>
  ...
</project>
 
Or follow steps 1-4 as per given link: https://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException

Problem: Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven.

Solution

1. Add following properties

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

2. Add default goal under build tag:

<build>
<defaultGoal>install</defaultGoal>

</build>

3. Make sure you have the necessary dependencies.

4. Clean Project: Project> clean

5. Update Project: Right click on Project>Maven> update Project

6. Build and run the project

Related Link: Click here..


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 exist

Solution: 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 Gradleremove all the External JARs from the Java Build PathMaven 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> from pom.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 cleanmaven install and then maven test.

Source: https://stackoverflow.com/questions/47823506/exception-in-thread-main-java-lang-noclassdeffounderror-org-openqa-selenium-w

Share the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *