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
.
JAR files are just ZIP files. Use a tool like WinZip to extract all the files from the JAR, replace the . class file with yours, recreate the ZIP file using e.g. WinZip, rename it to . jar, overwrite the original JAR file.
We can use this command with the t and f options to list the content of a JAR file: $ jar tf stripe-0.0. 1-SNAPSHOT. jar META-INF/ META-INF/MANIFEST.
Installing a module on WildFly / JBoss EAP requires creating a path under the JBOSS_HOME/modules folder. Under this path, you will install the JAR libraries which are part of the module and a module. xml file which describes the module itself and dependencies with other module. Within the module.
JBoss Deployment Structure File xml is a JBoss specific deployment descriptor that can be used to control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following: Prevent automatic dependencies from being added.
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:
WEB-INF/lib/*.jar
.bar.jar
in there, you don't know if it will be loaded before or after foo.jar
.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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With