maven - How to precompile a file after filtering? -
i building .war file contains .jsp file. in .jsp, there maven property variables, need filter using maven war plugin. besides that, precompile it, using mojo jspc plugin, , pack .class file war file.
however, filtered file not compiled. result war file consists filtered .jsp file , non filtered .class file.
how should configure pom.xml in order compile filtered .jsp?
my pom file shown below:
<build> <finalname>${component}</finalname> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <configuration> <archiveclasses>true</archiveclasses> <attachclasses>true</attachclasses> <packagingexcludes>**/*.vpp,web-inf/web.xml,**/eclipselink.jar,**/coherence.jar,** /toplink-grid.jar</packagingexcludes> <outputfilenamemapping>@{artifactid}@.@{extension}@</outputfilenamemapping> <webresources> <resource> <directory>src/main/webapp/verification</directory> <targetpath>verification</targetpath> <filtering>true</filtering> </resource> </webresources> <executions> <execution> <phase>process-resources</phase> </execution> </executions> </configuration> </plugin> <!-- start jspc --> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>jspc-maven-plugin</artifactid> <executions> <execution> <id>jspc</id> <goals> <goal>compile</goal> </goals> <phase>compile</phase> </execution> </executions> </plugin> <!-- end jspc --> </plugins> </build>
the jsp file stored in src/main/webapp/verification
it probable plugins execute in wrong order. plugins allow change phase bind to, adding e.g. <phase>generate-resources</phase>
. need explicitly bind plugins phases in such way execute filtering first. phases documented here. choose appropriate ones bind to. btw, filtering jsps directly pretty bad practice. instead, generate .properties file (filter it, or generate dynamically) , load servlet context, it's available jsps. if using spring, breeze. example below (runtime.properties filtered/generated file):
<bean class="org.springframework.web.context.support.servletcontextattributeexporter"> <property name="attributes"> <map> <entry key="config"> <util:properties location="classpath:runtime.properties"/> </entry> </map> </property> </bean>
you access in jsps config['somekey']
. eliminated need worry phase jsps filtered.
Comments
Post a Comment