maven jspc

Usage

NOTE: The configuration for version 2.0 of the jspc-maven-plugin has changed and you will need to update your pom.xml configuration to use the plugin correctly.

WAR Projects

You must use this plugin in conjunction with the maven-war-plugin . The maven-war-plugin must have its webXml configuration parameter set to the newly created web.xml , which is ${pom.basedir}/target/jspweb.xml by default.

<plugin>
    <groupId>org.codehaus.mojo.jspc</groupId>
    <artifactId>jspc-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                 <goal>compile</goal>
            </goals>
        </execution>
    </executions>
    
    <!-- Use the Tomcat 6 JSP compiler -->
    <dependencies>
        <dependency>
            <groupId>org.codehaus.mojo.jspc</groupId>
            <artifactId>jspc-compiler-tomcat6</artifactId>
        </dependency>
    </dependencies>
</plugin>

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

If you are using Servlet 2.4 or later, there is no need to place a web fragment tag in your web.xml file. The plugin will simply append it at the end.

However, if you want a specific location in your web.xml file that you want to inject your web fragment, you can do so by placing a tag that tells the JSPC plugin where to inject the servlet/jsp mapping.

First, in the pom, you need to set the configuration parameter to the fragment tag to look for, such as:

<!-- [INSERT FRAGMENT HERE] -->

However, keep in mind that since the pom is based on XML, you need to escape your XML. Your setup would look like the following:

<configuration>
    <webXml>${basedir}/target/jspweb.xml</webXml>
    <injectString>&lt;!-- [INSERT FRAGMENT HERE] --&gt;</injectString>
</configuration>

Then in your web.xml file, you need to place the tag where you want the injection to occur. A good place is generally right after your last declared servlet and before the servlet-mapping. Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
    <servlet>
        <!-- servlets defined here -->
    </servlet>
    
    <!-- [INSERT FRAGMENT HERE] -->
    
    <servlet-mapping>
        <!-- mappings defined here -->
    </servlet-mapping>
</web-app>

Non-WAR Projects

You can also use this plugin with non-war projects, for instance to validate JSPs. They will be compiled, but not included in your final artifact, and no web.xml file will be generated or modified.

If you want to just validate and compile your JSPs without actually including the generated code in your war project, you can also use set the includeInProject parameter to false.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值