删除jetty中web.xml中的过滤器

时间:2012-10-18 12:47:26

标签: maven jetty web.xml

我已经使用jetty maven配置了jetty来运行我的Web应用程序。 Jetty应该是开发的一个明智选择,因此它不需要web.xml中的所有东西。更具体地说,我想删除web.xml中的过滤器。

我尝试使用overrideDescriptor配置属性,但这只允许我覆盖web.xml,而不是替换它。因此,过滤器仍在那里。

如何在不修改原始web.xml文件的情况下删除过滤器的任何想法?

3 个答案:

答案 0 :(得分:1)

由于没有答案,我会发布我的解决方案,这并不完美。

<!-- Jetty configuration -->
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.5.v20120716</version>
    <configuration>
        <webApp>
            <descriptor>src/main/webapp/mock-web.xml</descriptor>
            [...]
        </webApp>
        [...]
    </configuration>
</plugin>

这种方法的缺点是你必须维护两个几乎相同的web.xml文件。我没有找到允许我覆盖原始web.xml文件并删除监听器的解决方案。

答案 1 :(得分:0)

一个强大的解决方案是在web.xml中使用2个XML实体:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document [
<!ENTITY webEntity1 SYSTEM 'webEntity1.xml'>
<!ENTITY webEntity2 SYSTEM 'webEntity2.xml'>
]>
<web-app>
    &webEntity1;
    &webEntity2;
</web-app>

custom-web.xml文件中只有一个:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document [
<!ENTITY webEntity1 SYSTEM 'webEntity1.xml'>
]>
<web-app>
    &webEntity1;
</web-app>

这样,在webEntity1.xml中,您将声明共享的servlet,过滤器,映射,并在webEntity2.xml中仅声明您不想在Jetty中使用的过滤器。

然后你会像这样配置jetty插件:

    <configuration>
        ...
        <webApp>
            ...
            <descriptor>${project.basedir}/src/main/webapp/WEB-INF/custom-web.xml</descriptor>
        </webApp>
        ...
    </configuration>

我刚刚在jetty plugin wiki page添加了一个部分。

答案 2 :(得分:0)

您可以将override-class替换为override-web.xml中的PassThroughFilter:

public class PassThroughFilter implements Filter{

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {}

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {}
}
<filter>
    <filter-name>OriginalFilter</filter-name>
    <filter-class>mypackage.PassThroughFilter</filter-class>        
</filter>