How to replace an existing Java class?

Last modified by Vincent Massol on 2015/09/17

Imagine that you want to make changes to an existing Java class and deploy the modified version in your XWiki instance.

You have several options:

  1. Put the modified compiled .class file in XWiki's WEB-INF/classes directory. Anything in that directory has precedence over the JARs in WEB-INF/lib (see the Servlet Specifications).
  2. Rebuild the XWiki module where you have modified a class and deploy that JAR over the existing one in WEB-INF/lib
    • If you can't find that JAR make sure to check for a legacy JAR. For example if you can't find xwiki-platform-oldcore.jar, search for xwiki-platform-legacy-oldcore.jar.
    • You'll need to rebuild the legacy module from sources (of course you also need to rebuild the module where you made the modification first). These legacy modules use AspectJ to inject APIs that have been deprecated and the produced JAR wraps the original non-legacy JAR.
    • Once you've rebuilt the legacy module, just deploy its JAR in WEB-INF/lib so that it replaces the existing JAR there.

If you're just changing a few files, the first option with WEB-INF/classes is recommended.

Get Connected