If the class to override is called com.example.FooServlet
and this class is inside a jar WEB-INF/lib/foo.jar
, how to override it with a class also called com.example.FooServlet
in another jar, say bar.jar
?
Or is there any way to make sure the one in bar.jar
is loaded first?
Making bar.jar
a module is no-go because the FooServlet
imports tons of classes from many jars in WEB-INF/lib
.
As I stated above, I tried to contain bar.jar
in a module, but got class not found or no class def error (can't remember clearly) as FooServlet
extends/implements some extra classes/interfaces which are in 3rd party jars in WEB-INF/lib.
I'm not allowed to touch foo.jar
or any of the jars that are already existing in WEB-INF/lib
.
You said you cannot touch existing jars, and you seem to imply you can add a jar of yours to WEB-INF/lib
.
According to this:
- there is no specified order of precedence for jars under
WEB-INF/lib/*.jar
.
So if you addbar.jar
in there, you don't know if it will be loaded before or afterfoo.jar
. - the servlet spec says classes under
WEB-INF/classes
must be loaded before anything underWEB-INF/lib/*.jar
Assuming you can add a jar under WEB-INF/lib
, you should be able to add a class (or several) under WEB-INF/classes
, without touching the ones in place.
So, if you want the classes from bar.jar
to be loaded first, you can unzip the contents of that jar under WEB-INF/classes
instead (or just the class you want to be loaded in priority -- for example WEB-INF/classes/com/example/FooServlet.class
).