package my;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class NewClass implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Start");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("End");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<listener>
<listener-class>my.NewClass</listener-class>
</listener>
</web-app>