How to Solve Error Message Error injecting: org.apache.maven.plugin.war.WarMojo when Build and Compile Java Application using Maven Builder

Posted on

Introduction

This article is actually an additional article. It is very important to add the solution for solving an error in another article. Actually, there is an article How to Solve Error Message Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project myapp: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin:2.2’ due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties when Build and Compile Java Application. Furthermore, the actual error message which is the focus for further solution is in this article. Below is the actual error message appear :

Error injecting: org.apache.maven.plugin.war.WarMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:
...
...
...

How to Solve Error Message Error injecting: org.apache.maven.plugin.war.WarMojo

Basically, the problem exist in the ‘pom.xml’ file. The solution in the previous article mentioned to edit the ‘pom.xml’ as follows :

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>projectf</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>myapp</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>hjojoj
    </properties>
 
    <dependencies>
         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-api</artifactId>
             <version>7.0</version>
             <scope>provided</scope>
         </dependency>
    </dependencies>
    <build>
         <resources>
             <resource>
                 <filtering>true</filtering>
                 <directory>src/main/resources</directory>
             </resource>
             <resource>
                 <directory>src/main/docs</directory>
                 <filtering>true</filtering>
             </resource>
             <resource>
                 <directory>src/main/java</directory>
                 <includes>
                     <include>**/*.xml</include>
                     <include>**/*.properties</include>
                 </includes>
             </resource>
         </resources>
         <testResources>
             <testResource>
                  <filtering>true</filtering>
                  <directory>src/test/resources</directory>
             </testResource>
             <testResource>
                  <directory>src/test/java/</directory>
             </testResource>
         </testResources>
         <plugins>
             <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.3</version>
                  <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                  </configuration>
             </plugin>
         </plugins>
         <finalName>myapp</finalName>
    </build>
    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>https://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
   </repositories>
</project>

 

As for the solution, just another snippet code of pom.xml file configuration. The following are those lines of configuration which is adding a plugin as follows :

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

In that case, the complete modification of the ‘pom.xml’ will exist as follows :

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>projectf</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>myapp</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>hjojoj
    </properties>
 
    <dependencies>
         <dependency>
             <groupId>javax</groupId>
             <artifactId>javaee-api</artifactId>
             <version>7.0</version>
             <scope>provided</scope>
         </dependency>
    </dependencies>
    <build>
         <resources>
             <resource>
                 <filtering>true</filtering>
                 <directory>src/main/resources</directory>
             </resource>
             <resource>
                 <directory>src/main/docs</directory>
                 <filtering>true</filtering>
             </resource>
             <resource>
                 <directory>src/main/java</directory>
                 <includes>
                     <include>**/*.xml</include>
                     <include>**/*.properties</include>
                 </includes>
             </resource>
         </resources>
         <testResources>
             <testResource>
                  <filtering>true</filtering>
                  <directory>src/test/resources</directory>
             </testResource>
             <testResource>
                  <directory>src/test/java/</directory>
             </testResource>
         </testResources>
         <plugins>
             <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.3</version>
                  <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                  </configuration>
             </plugin>
             <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-war-plugin</artifactId>
                  <version>3.3.1</version>
                  </plugin>
         </plugins>
         <finalName>myapp</finalName>
    </build>
    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>https://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
   </repositories>
</project>

Off course in the dependency section, just add the suitable library package for the Java application. After that, just build and compile it once more. If there are no further error message, the process for building and compiling the Java application will end in a success.

Leave a Reply