Solving Unable to load the mojo ‘war’ in the plugin

If you’re migrating a Java EE or Jakarta EE project to Java 17 or later, and you’re using Maven 3.8 or newer, you might encounter the following error during a mvn package or mvn install: ” Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin‘. This issue is often triggered when your project implicitly uses an outdated version of the maven-war-plugin that is incompatible with newer Java versions or Maven APIs.

Problem Description

The error stems from incompatibility between the plugin’s internal APIs (Plexus or ASM) and the newer Java class structure introduced in Java 17+. When the maven-war-plugin is not explicitly declared in your POM, Maven defaults to an older version (often < 3.3), which attempts to load classes using techniques no longer supported in Java 17.

Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.4:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.4' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

🔎 Diagnosing the Problem with effective-pom

To confirm which version of the maven-war-plugin is being used (especially if it’s not declared), run the following command:

mvn help:effective-pom

Look for the <plugins> section. If no explicit version is shown for maven-war-plugin, Maven is falling back to its default (usually outdated) version. That’s likely the root of your problem.

Solution Steps

To resolve this error, you need to update the Maven War Plugin to the latest version. Follow the steps below:

  1. Open your project’s pom.xml file in a text editor or integrated development environment (IDE) of your choice.
  2. Locate the <build> section within the pom.xml file. If it doesn’t exist, create one as a child element of the <project> element.
  3. Inside the <build> section, find the <plugins> element. If it doesn’t exist, create it as a child element of the <build> element.
  4. Within the <plugins> section, locate the following entry for the Maven War Plugin:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
</plugin>

Update the version of the Maven War Plugin to the latest stable version. You can find the latest version by visiting the Maven War Plugin’s official documentation or by checking the Maven Central Repository.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.4.0</version>
</plugin>

Save the pom.xml file.

Open a command-line interface (CLI) and navigate to the root directory of your project, where the pom.xml file is located.

Run the Maven build command to test if the error has been resolved:

mvn clean install

The build should now execute without encountering the previous error.

Alternative Fixes

In addition to declaring the plugin version, here are a few alternative approaches:

Use pluginManagement in a parent POM
If you manage multiple projects, you can centralize plugin version control like so that you don’t need to repeat the Plugin declaration in every module.

Upgrade Maven
If you’re still using Maven 3.6 or earlier, upgrade to Maven 3.8.7 or later, which improves default plugin handling and Java 17+ support.

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>3.4.1</version>
    </plugin>
  </plugins>
</pluginManagement>

Conclusion

In this article, we addressed the error message “Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin’ due to an API incompatibility” encountered during a Maven build. We provided a step-by-step solution by updating the Maven War Plugin to the latest version. By following these steps, you

Was this article helpful? We need your support to keep MasterTheBoss alive!