Search code examples
tomcatxwiki

Xwiki reload component jar


According to the guide, adding new components to XWiki involves putting the jar file into XE_WAR_HOME/WEB-INF/lib. However I seem to then need to restart tomcat before I can use the new component. Is there a way around this restart? The component manager manages to install new components from a repository without restarting tomcat, so it seems possible in principle...

On a related point, even restarting tomcat doesn't appear to update an existing component if I replace a jar with an updated version with the same name. So can I explicitly trigger a reload in this case?


Solution

  • The guide has been updated in the mean time and show how todo this.

    In a nutshell: add your local maven repo to the xwiki.properties:

    extension.repositories=local:maven:file://${sys:user.home}/.m2/repository
    extension.repositories=maven-xwiki:maven:http://nexus.xwiki.org/nexus/content/groups/public
    extension.repositories=extensions.xwiki.org:xwiki:http://extensions.xwiki.org/xwiki/rest/ 
    

    (the other two lines are needed to re-add the "default" repos)

    In the Wiki UI, install the Extension Tweak

    Then for each build cycle:

    • build your extension via mvn install
    • go to the Extension section in the Wiki
    • look up your extension in the "Advanced search" (your local maven repo is not searchable, so you need to tell the full id - i.e. my.extension.group:my-extension-id and version - ie. 0.1-SNAPSHOT)
    • remove the currently installed extension
    • flush the cache via the /xwiki/bin/view/Admin/InstalledExtensionsTweak
    • look up your extension in the "Advanced search" again, and install it

    Because I didn't want to limit my answer to copying the "Howto" in the guide, here is a small script that should do the "reinstall" part (i.e. use it after running mvn install) for you:

    # "config" section:
    
    # variables should be URL encoded; '%3A' is ':' 
    EXTENSION_ID=org.xwiki.contrib%3Aapplication-mocca-calendar-ui
    VERSION=2.5-SNAPSHOT
    BASE_URL=http://localhost:8080/xwiki
    
    # of course you can use curl here if you prefer
    WGET="wget -q -O /dev/null --auth-no-challenge --http-user=Admin --http-password=admin"
    # alternative for debugging
    #WGET="wget -S -O - --auth-no-challenge --http-user=Admin --http-password=admin"
    
    QUERY="extensionId=${EXTENSION_ID}&extensionVersion=${VERSION}&extensionNamespace=wiki%3Axwiki&form_token=dummy"
     
    set -o errexit
    
    # first remove the old version of the extension
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=uninstall&${QUERY}"
    
    # confirm uninstall
    sleep 1
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=continue&${QUERY}"
    # confirm uninstall again (this time to "remove unused pages") 
    sleep 1
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=continue&${QUERY}"
    
    # flush the cache
    $WGET "${BASE_URL}/bin/get/Admin/InstalledExtensionsTweak?basicauth=1&eaction=clean_confirm"
    
    # add new version
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=install&${QUERY}"
    
    # confirm: start adding
    sleep 1
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=continue&${QUERY}"
    
    # just in case we get a conflict: overwrite with new version
    sleep 1.5
    $WGET "${BASE_URL}/bin/get/XWiki/AddExtensions?basicauth=1&extensionAction=continue&autoResolve=true&versionToKeep=NEXT&${QUERY}"
    

    If you want to use this script, your must disable CSRF-Protection in xwiki.properties by setting: csrf.enabled = false. (Alternatively you could modify the script by reading the csrf-token from the HTML in the response.)

    The script has no error handling. If you see no update after executing it, perform the steps outlined above to figure out what went wrong.

    Addendum: at least with XWiki 14.x the get/XWiki/AddExtensions should be replaced with get/XWiki/Extensions