ClassLoader API
Last modified by Thomas Mortagne on 2021/08/19 11:09
![]() | 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 jars="groupId:artifactId:version"}}
...
{{/groovy}}
...
{{/groovy}}
To do so, Implements a component implementing the org.xwiki.classloader.ExtendedURLStreamHandler role.
Example: AttachmentURLStreamHandler
@Component
@Named("attachmentjar")
@Singleton
public class AttachmentURLStreamHandler extends URLStreamHandler implements ExtendedURLStreamHandler
...
{{code}}
@Named("attachmentjar")
@Singleton
public class AttachmentURLStreamHandler extends URLStreamHandler implements ExtendedURLStreamHandler
...
{{code}}