Q:

Project Not Detecting Java Filter

I'm developing a project using AspectJ where I use a filter for the http requests and responses. Basically I'm turning this project into a .jar and using this jar in a benchmark app where I perform some security tests. When I declare the filter on the benchmark app and on its web.xml it works fine, but if I put it in the project I'm developing (the jar file), then the benchmark app won't detect it... I've been told that if you use the latest version of web.xml, you don't need to declare the filter on web.xml and it should detect it automatically but it's not working. How can I get this to work?
The version I'm using in web.xml is this:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">

filter class:
package main.java.filter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import main.java.Configuration;
import main.java.HashTableCreation;

/**
* Servlet Filter implementation class MyFilter
*/
@WebFilter("/MyService/*")
public class MyFilter implements Filter
{

/**
 * Default constructor. 
 */
public MyFilter() {
}

/**
 * @see Filter#destroy()
 */
public void destroy() {
    // TODO Auto-generated method stub

}

/**
 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    System.out.println("###### FILTER before NO DRIVER...");

//      HttpServletRequest req = (HttpServletRequest) request;
//      
//      String loggedIn = (String) req.getSession().getAttribute("login");
//      
//      if (loggedIn == null)
//      {
//          req.getRequestDispatcher("notLoggedIn.jsp").forward(request, response);;
//      }*/

    chain.doFilter(request, response);

    System.out.println("###### FILTER after...");

}

/**
 * @see Filter#init(FilterConfig)
 */
public void init(FilterConfig fConfig) throws ServletException {
    System.out.println("Initializing filter...");

}

}

A:

When you have a jar file in this case, it's simply a library. The servlet container isn't looking in your jar file for a web.xml file. That's simply not how it works. As you describe, your web.xml file must reference the filter explicitly otherwise the servlet container won't know to load it. 
If you're trying to use annotation-based loading, per the spec, referenced in this post, it must be in WEB-INF/classes or in WEB-INF/lib as a jar.

