ClassLoader API

Last modified by Thomas Mortagne on 2023/09/18 12:51

cogManage class loaders manipulated by XWiki and add ability to register URL stream handlers
Developed by

XWiki Development Team

0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard


Exists since XWiki 2.0.1.


This module manage class loaders manipulated by XWiki and generally associated to namespaces. In addition, it allows registering new URL Stream handlers (this is used for example by the jars parameter of the Script Macro).

Adding a new URL Stream Handler

This is useful for example if you wish to add a new way to reference a JAR when using the Script Macro. For example imagine you wish to retrieve the JAR from a remote Maven Repository by passing only a groupId, artifactId and a version. You could implement a new Stream Handler to be able to write something like:

{{groovy jars="groupId:artifactId:version"}}

To do so, Implements a component implementing the org.xwiki.classloader.ExtendedURLStreamHandler role. 

Example: AttachmentURLStreamHandler

public class AttachmentURLStreamHandler extends URLStreamHandler implements ExtendedURLStreamHandler

Classloader name

ClassLoaders associated to namespaces are of type org.xwiki.classloader.NamespaceURLClassLoader and expose a getNamespace() method to access the namespace.

XWiki 15.8+ They also implement the more standard Classloader#getName() introduce in Java 9, so you don't need to cast it to a NamespaceURLClassLoader to access the name.

Get Connected