If you want to find out where the class is being loaded from, try
java -verbose:class -jar foo.jar | grep javax.servlet.ServletContext
where foo.jar
is the fat JAR produced by Gradle or Maven. For example, the ServletContext
class could be getting read from an older servlet-api
JAR in a JDK extensions directory instead of your Maven or Gradle dependencies.
The output of the command looks something like this...
$ java -verbose:class -jar build/libs/foo-0.2.3.jar | grep javax.servlet.ServletContext
[Loaded javax.servlet.ServletContext from jar:file:.../build/libs/foo-0.2.3.jar!/lib/javax.servlet-api-3.1.0.jar!/]
[Loaded javax.servlet.ServletContextListener from jar:file:.../build/libs/foo-0.2.3.jar!/lib/javax.servlet-api-3.1.0.jar!/]
[Loaded javax.servlet.ServletContextAttributeListener from jar:file:.../build/libs/foo-0.2.3.jar!/lib/javax.servlet-api-3.1.0.jar!/]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…