Maven WAR Plugin
  1. Maven WAR Plugin
  2. MWAR-246

NullPointerException Processing Web Resources

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux, JDK 6
    • Number of attachments :
      0

      Description

      NullPointerException on packaging of web resources. Configuration is:

               <plugin>
                  <artifactId>maven-war-plugin</artifactId>
                  <configuration>
                     <webResources>
                        <resource>
      	                  <excludes>
      	                     <exclude>xercesImpl-*.jar</exclude>
      	                  </excludes>
                        </resource>
                     </webResources>
                  </configuration>
               </plugin>
      

      Stack trace is:

      Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war failed.
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:211)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
      	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
      	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
      	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
      	at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
      Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war failed.
      	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:116)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
      	... 19 more
      Caused by: java.lang.NullPointerException
      	at java.io.File.<init>(File.java:222)
      	at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.handleWebResources(WarProjectPackagingTask.java:124)
      	at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.performPackaging(WarProjectPackagingTask.java:91)
      	at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:472)
      	at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:404)
      	at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:197)
      	at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:159)
      	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
      	... 20 more
      

        Issue Links

          Activity

          Hide
          Stéphane Nicoll added a comment -

          you miss the directory. webResources is just a regular resource section. That being said, the plugin should fail with a proper error message.

          What are you trying to accomplish exactly? Remove stuff from the generated war?

          You may want to look at packagingExcludes
          http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#packagingExcludes

          Show
          Stéphane Nicoll added a comment - you miss the directory. webResources is just a regular resource section. That being said, the plugin should fail with a proper error message. What are you trying to accomplish exactly? Remove stuff from the generated war? You may want to look at packagingExcludes http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#packagingExcludes
          Hide
          Gary Murphy added a comment -

          Thank you for the quick response. I discovered yesterday that packagingExcludes was what I was really looking for. I agree with you regarding the need for a proper error message, so that's why I cut the JIRA.

          Show
          Gary Murphy added a comment - Thank you for the quick response. I discovered yesterday that packagingExcludes was what I was really looking for. I agree with you regarding the need for a proper error message, so that's why I cut the JIRA.
          Hide
          Michael Glauche added a comment -

          QnD patch:

          Index: src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java
          ===================================================================
          --- src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java	(revision 1072684)
          +++ src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java	(working copy)
          @@ -121,6 +121,11 @@
                   for ( int i = 0; i < webResources.length; i++ )
                   {
                       Resource resource = webResources[i];
          +            
          +            if (resource.getDirectory() == null) {
          +                throw new MojoExecutionException( "Directory tag is missing from Resource decleration" );
          +            }
          +            
                       if ( !( new File( resource.getDirectory() ) ).isAbsolute() )
                       {
                           resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() );
          

          Although http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html does state the following example:

                  ...
                  <configuration>
                    <webResources>
                      <resource>
                        <!-- the default value is ** -->
                        <includes>
                          <include>**/pattern1</include>
                          <include>*pattern2</include>
                        <includes>
                        <!-- there's no default value for this -->
                        <excludes>
                          <exclude>*pattern3/pattern3</exclude>
                          <exclude>pattern4/pattern4</exclude>
                        </excludes>
                      </resource>
                    </webResources>
                  </configuration>
                  ...
          

          Which does give a NPE in any case with maven-war-plugin 2.1.1, i think the example should also contain a directory tag, or ?

          Show
          Michael Glauche added a comment - QnD patch: Index: src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java =================================================================== --- src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java (revision 1072684) +++ src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java (working copy) @@ -121,6 +121,11 @@ for ( int i = 0; i < webResources.length; i++ ) { Resource resource = webResources[i]; + + if (resource.getDirectory() == null ) { + throw new MojoExecutionException( "Directory tag is missing from Resource decleration" ); + } + if ( !( new File( resource.getDirectory() ) ).isAbsolute() ) { resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() ); Although http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html does state the following example: ... <configuration> <webResources> <resource> <!-- the default value is ** --> <includes> <include>**/pattern1</include> <include>*pattern2</include> <includes> <!-- there's no default value for this --> <excludes> <exclude>*pattern3/pattern3</exclude> <exclude>pattern4/pattern4</exclude> </excludes> </resource> </webResources> </configuration> ... Which does give a NPE in any case with maven-war-plugin 2.1.1, i think the example should also contain a directory tag, or ?
          Hide
          Stéphane Nicoll added a comment -

          Absolutely, good catch.

          Show
          Stéphane Nicoll added a comment - Absolutely, good catch.
          Hide
          Dennis Lundberg added a comment -

          Patch applied in r1390132. Thanks!

          I also added a <directory> tag in the example.

          Show
          Dennis Lundberg added a comment - Patch applied in r1390132 . Thanks! I also added a <directory> tag in the example.

            People

            • Assignee:
              Dennis Lundberg
              Reporter:
              Gary Murphy
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: