How to override some classes in a jar in WEB-INF/lib with another jar in JBoss EAP?

coolcfan :

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.

Hugues M. :

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 add bar.jar in there, you don't know if it will be loaded before or after foo.jar.
  • the servlet spec says classes under WEB-INF/classes must be loaded before anything under WEB-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).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=471398&siteId=1