How to Solve Error Message error: -endorseddirs requires an argument when building Java Web Application in NetBeans

Posted on

Introduction

This is an article which has a connection with several previous article. The first one is an article with the title of ‘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’ in this link. The second one is an article with the title of ‘How to Solve Error Message Unable to find artifact version of javax:javaee-api in either dependency list or in project’s dependency management when building Java Application in NetBeans’ in this link. On the other hand, the error appear in this article actually exist as follows :

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project app: Fatal error compiling: error: -endorseddirs requires an argument -> [Help 1]

Solution

Actually, the error exist in the introduction part has something to do with editing the ‘pom.xml’ file. It is commenting the endorseddirs property definition in the ‘pom.xml’ file. In order to solve an error where the API compability is not suitable of the maven-war-plugin with the Jakarta EE as exist in this link, comment a certain part of property definition 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>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>

So, instead of commenting all of the properties, just comment the Jakarta EE version as in the following one :

    <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>

Leave a Reply