You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by George Berger <gc...@bigfoot.com> on 2007/02/07 17:02:25 UTC

jsp precompile with war overlay

I'm trying to use the war overlay feature of maven-war-plugin to include some
common JSPs (e.g. common header and footer files) in multiple projects, but
I also want to use jspc-maven-plugin to precompile the project JSPs.

The issue I'm facing is that jspc-maven-plugin needs to run after the war
overlay is done, so that the common JSPs are available during the
precompile, but before the packaging is done, so the generated classes and
web.xml get included in the final war.

Without using war overlays, the build section of my project pom looks like
this in order to do the precompile:

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jspc-maven-plugin</artifactId>
        <version>1.4.6</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webXml>${basedir}/target/jspweb.xml</webXml>
        </configuration>
      </plugin>
    </plugins>
  </build>

The <webXml> configuration for maven-war-plugin causes the war plugin to use
the web.xml file generated by the jspc plugin -- jspc rewrites the web.xml
to add servlet mappings for the precompiled JSP classes.

This works well when all the JSPs are present in the project -- the
generated war contains the precompiled JSP classes plus the rewritten
web.xml.

In order to get the precompile to work with JSPs from an overlaid war, I
tried declaring an execution of the war plugin's "exploded" goal during the
process-resources phase so that it builds a directory tree containing the
overlays for the war:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

I added some configuration to the jspc plugin to get it to compile the JSPs
from the exploded tree instead of from src/main/webapps:

        <configuration>
          <warSourceDirectory>
            ${basedir}/target/${artifactId}-${version}
          </warSourceDirectory>
        </configuration>

Here's the complete build section of my project pom after adding those
changes:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jspc-maven-plugin</artifactId>
        <version>1.4.6</version>

        <configuration>
          <warSourceDirectory>
            ${basedir}/target/${artifactId}-${version}
          </warSourceDirectory>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webXml>${basedir}/target/jspweb.xml</webXml>
        </configuration>
      </plugin>
    </plugins>
  </build>


This works great, almost: the overlaid war directory gets created, jspc
precompiles its JSPs, and the war plugin creates the final war containing
all the precompiled JSP classes in its WEB-INF/classes directory.

The only problem is that the war contains the original web.xml from
src/main/webapps/WEB-INF instead of the rewritten version created by jspc,
even though the configuration to use the rewritten one still exists in the
second maven-war-plugin declaration.

Any ideas why this is happening or how to get around it?

George

-- 
View this message in context: http://www.nabble.com/jsp-precompile-with-war-overlay-tf3187860s177.html#a8848176
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: jsp precompile with war overlay

Posted by George Berger <gc...@bigfoot.com>.

franz see wrote:
> 
> Good day to you, George,
> 
> My guess is that maven got confused since you declared maven-war-plugin
> twice in the build section. You may want to combine both execution under
> one <plugin> and differentiate one from the other by using an <id/>. 
> 
> Something like this...
> 
>   <build>
>  [snip]
>   </build> 
> 
> Cheers,
> Franz
> 
> 

That works perfectly!  Many thanks Franz.  A good day indeed!

George

-- 
View this message in context: http://www.nabble.com/jsp-precompile-with-war-overlay-tf3187860s177.html#a8875042
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: jsp precompile with war overlay

Posted by franz see <fr...@gmail.com>.
Good day to you, George,

My guess is that maven got confused since you declared maven-war-plugin
twice in the build section. You may want to combine both execution under one
<plugin> and differentiate one from the other by using an <id/>. 

Something like this...

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
          <execution>
            <id>build-directory-tree</id>
            <phase>process-resources</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
          <execution>
            <id>build-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              <webXml>${basedir}/target/jspweb.xml</webXml>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jspc-maven-plugin</artifactId>
        <version>1.4.6</version>

        <configuration>
          <warSourceDirectory>
            ${basedir}/target/${artifactId}-${version}
          </warSourceDirectory>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build> 

Cheers,
Franz

George Berger wrote:
> 
> 
> Jörg Schaible wrote:
>> 
>> 
>> Can't you simply exclude the web.xml from the overlay?
>> 
>>  <plugin>
>>     <artifactId>maven-war-plugin</artifactId>
>>     <configuration>
>>        <dependentWarExcludes>WEB-INF/web.xml</dependentWarExcludes>
>>     </configuration>
>>  </plugin>
>> 
>> - Jörg
>> 
>> 
> 
> Hi Jörg -
> 
> Thanks for the suggestion.  I tried it but got the same result.
> 
> What I want the plugin to do is use the web.xml file generated by jspc,
> which is what this configuration tries to do:
> 
>         <artifactId>maven-war-plugin</artifactId>
>         <configuration>
>             <webXml>${basedir}/target/jspweb.xml</webXml>
>         </configuration>
> 
> I found that this works fine if I'm just doing the precompile and the war
> packaging -- the jspc-generated jspweb.xml file gets used as the web.xml
> in the packaged war.  But when I add the additional declaration to the pom
> to run the war:exploded goal during the process-resources phase, the final
> packaging uses the web.xml from the src/main/webapp tree instead.  Any
> idea why the above configuration works in the first case but not in the
> second?
> 
> George
> 
> 

-- 
View this message in context: http://www.nabble.com/jsp-precompile-with-war-overlay-tf3187860s177.html#a8869466
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: jsp precompile with war overlay

Posted by George Berger <gc...@bigfoot.com>.

Jörg Schaible wrote:
> 
> 
> Can't you simply exclude the web.xml from the overlay?
> 
>  <plugin>
>     <artifactId>maven-war-plugin</artifactId>
>     <configuration>
>        <dependentWarExcludes>WEB-INF/web.xml</dependentWarExcludes>
>     </configuration>
>  </plugin>
> 
> - Jörg
> 
> 

Hi Jörg -

Thanks for the suggestion.  I tried it but got the same result.

What I want the plugin to do is use the web.xml file generated by jspc,
which is what this configuration tries to do:

        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webXml>${basedir}/target/jspweb.xml</webXml>
        </configuration>

I found that this works fine if I'm just doing the precompile and the war
packaging -- the jspc-generated jspweb.xml file gets used as the web.xml in
the packaged war.  But when I add the additional declaration to the pom to
run the war:exploded goal during the process-resources phase, the final
packaging uses the web.xml from the src/main/webapp tree instead.  Any idea
why the above configuration works in the first case but not in the second?

George

-- 
View this message in context: http://www.nabble.com/jsp-precompile-with-war-overlay-tf3187860s177.html#a8867524
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org