ClassLoader API
Manage class loaders manipulated by XWiki and add ability to register URL stream handlers |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Compatibility | Exists since XWiki 2.0.1. |
Table of contents
Description
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}}
To do so, Implements a component implementing the org.xwiki.classloader.ExtendedURLStreamHandler role.
Example: AttachmentURLStreamHandler
@Named("attachmentjar")
@Singleton
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.