How to Solve Error Message Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project app: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.3’ due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null when compiling and building Java Web Application in NetBeans

Posted on

Introduction

This is an article where the main focus is to solve an error message appear while compiling and building a Java Web Application in NetBeans IDE. The Java Web Application is using a Java EE platform. The process for creating the Java Web Application in NetBeans IDE, currently by default will use the new Java EE version. Recently, it is changed into another name where the details exist in an article in the following link.

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project app: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

But apparently, the process for compiling and building the Java Web Application ends in a failure. Before going on further, the following is the content of the ‘pom.xml’ file which is part of the project :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.web</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>app-1.0-SNAPSHOT</name>
    <properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <failOnMissingWebXml>false</failOnMissingWebXml>
         <jakartaee>8.0</jakartaee>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${jakartaee}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                      <compilerArguments>
                              <endorseddirs>${endorsed.dir}</endorseddirs>
                      </compilerArguments>
                 </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-war-plugin</artifactId>
                   <version>2.3</version>
                   <configuration>
                       <failOnMissingWebXml>false</failOnMissingWebXml>
                   </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-dependency-plugin</artifactId>
                   <version>2.6</version>
                   <executions>
                       <execution>
                          <phase>validate</phase>
                          <goals>
                             <goal>copy</goal>
                          </goals>
                          <configuration>
                               <outputDirectory>${endorsed.dir}</outputDirectory>
                               <silent>true</silent>
                               <artifactItems>
                                   <artifactItem>
                                       <groupId>javax</groupId>
                                       <artifactId>javaee-api</artifactId>
                                       <version>${jakartaee}</version>
                                       <type>jar</type>
                                   </artifactItem>
                               </artifactItems>
                           </configuration>
                        </execution>
                    </executions>
               </plugin>
           </plugins>
      </build>
</project>

Solution by changing maven-war-plugin and maven-dependency-plugin

After searching for the solution in the internet, actually there are two solutions in order to solve the problem. Generally speaking, the error message occurs because of the incompatibility of the Java EE with the version of maven-war-plugin and also maven-dependency-plugin. The solution exist as follows :

The first one is to upgrade the maven-war-plugin and also maven-dependency-plugin. Since it is the Jakarta EE which is the new version of Java EE, it also need the latest version of maven-war-plugin and also maven-dependency-plugin. So, check the latest version of maven-war-plugin and also maven-dependency-plugin in the maven repository site as it exist in this link. Why update the version only for those two package ?. The maven-war-plugin and also the maven-dependency-plugin ?. The reason is very simple as it exist as part of the error message below :

Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.3' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

The above error message is informing that the mojo ‘war’ in the plugin ‘in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.3’ cannot be loaded. The reason is because of the API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null. Since it is not compatible, one of the main reason is because of the version is not compatible with the rest of the package. In other words, the solution is by updating the version of the maven-war-plugin so it will be compatible for further execution. Another package which is related to maven package or plugin component is the ‘maven-dependency-plugin’ package or plugin component. Just update it also. So, the ‘pom.xml’ file of the project regarding the updated version of the ‘maven-war-plugin’ and ‘maven-dependency-plugin’ with the latest one exist as follows :

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
</dependency>

So, overall, it will be as follows :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.web</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>app-1.0-SNAPSHOT</name>
    <properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <failOnMissingWebXml>false</failOnMissingWebXml>
         <jakartaee>8.0</jakartaee>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${jakartaee}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                      <compilerArguments>
                              <endorseddirs>${endorsed.dir}</endorseddirs>
                      </compilerArguments>
                 </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-war-plugin</artifactId>
                   <version>3.3.2</version>
                   <configuration>
                       <failOnMissingWebXml>false</failOnMissingWebXml>
                   </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-dependency-plugin</artifactId>
                   <version>3.3.0</version>
                   <executions>
                       <execution>
                          <phase>validate</phase>
                          <goals>
                             <goal>copy</goal>
                          </goals>
                          <configuration>
                               <outputDirectory>${endorsed.dir}</outputDirectory>
                               <silent>true</silent>
                               <artifactItems>
                                   <artifactItem>
                                       <groupId>javax</groupId>
                                       <artifactId>javaee-api</artifactId>
                                       <version>${jakartaee}</version>
                                       <type>jar</type>
                                   </artifactItem>
                               </artifactItems>
                           </configuration>
                        </execution>
                    </executions>
               </plugin>
           </plugins>
      </build>
</project>

Solution by changing the Java EE version

The second solution simply by changing the Java EE version. Instead of using the new Java EE which is currently known as Jakarta EE, just use the old one. Comment the new Java EE or Jakarta EE version and add a declaration using the old Java EE as follows :

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

If the solution is changing the Java EE version, the following will be the modification of overall version of the ‘pom.xml’ file content :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.web</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>app-1.0-SNAPSHOT</name>
    <properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <failOnMissingWebXml>false</failOnMissingWebXml>
         <jakartaee>8.0</jakartaee>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                      <compilerArguments>
                              <endorseddirs>${endorsed.dir}</endorseddirs>
                      </compilerArguments>
                 </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-war-plugin</artifactId>
                   <version>2.3</version>
                   <configuration>
                       <failOnMissingWebXml>false</failOnMissingWebXml>
                   </configuration>
              </plugin>
              <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-dependency-plugin</artifactId>
                   <version>2.6</version>
                   <executions>
                       <execution>
                          <phase>validate</phase>
                          <goals>
                             <goal>copy</goal>
                          </goals>
                          <configuration>
                               <outputDirectory>${endorsed.dir}</outputDirectory>
                               <silent>true</silent>
                               <artifactItems>
                                   <artifactItem>
                                       <groupId>javax</groupId>
                                       <artifactId>javaee-api</artifactId>
                                       <version>${jakartaee}</version>
                                       <type>jar</type>
                                   </artifactItem>
                               </artifactItems>
                           </configuration>
                        </execution>
                    </executions>
               </plugin>
           </plugins>
      </build>
</project>

4 thoughts on “How to Solve Error Message Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project app: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.3’ due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null when compiling and building Java Web Application in NetBeans

Leave a Reply