Can't find descriptor for Parser error (when rendering XWiki to HTML)

Hi everyone,

I am trying to write a Java program to transform XWiki code into XHTML using the XWiki rendering framework.
I’ve followed the Getting started tutorial and created a project with maven to manage dependencies. I also tried downloading the standalone ZIP dependencies and use it in an Ant project.

In both cases, I have the following exception :

    org.xwiki.component.manager.ComponentLookupException: Can't find descriptor for the component [role = [interface org.xwiki.rendering.parser.Parser] hint = [xwiki/2.1]]
            at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:401)
            at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:190) 

The source code is fairly simple and can be seen on pastebin : import org.xwiki.component.embed.EmbeddableComponentManager;import org.xwiki.r - Pastebin.com
Essentially, reading a file that holds the XWiki code and converting it.

Running the code using eclipe’s integrated run, works fine. However, when I create a jar file (including all dependencies), the above error is always shown.
Any idea what might be causing it ?

Hi, this error means that you’re missing the xwiki/2.1 parser in your project’s dependencies.

Namely, you need to add the following dependency:

    <dependency>
      <groupId>org.xwiki.rendering</groupId>
      <artifactId>xwiki-rendering-syntax-xwiki21</artifactId>
      <version>...version here...</version>
    </dependency>

Hope it helps

Hi, thanks for your reply.

I already have the dependency in maven, and I also have it in my ant project. Still the same error.
My pom.xml is at: <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/ - Pastebin.com
My Main class: package com.catamania.convertXWiki;import java.io.StringReader;import java - Pastebin.com

With both the pom.xml and the Main class, I am getting the above error. Full stacktrace is:

org.xwiki.component.manager.ComponentLookupException: Failed to lookup component [org.xwiki.rendering.internal.parser.xwiki21.XWiki21Parser] identified by [role = [interface org.xwiki.rendering.parser.Parser] hint = [xwiki/2.1]]
        at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:394)
        at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:190)
        at com.catamania.convertXWiki.Main.convertMacro(Main.java:41)
        at com.catamania.convertXWiki.Main.main(Main.java:27)
Caused by: org.xwiki.component.manager.ComponentLookupException: Can't find descriptor for the component [role = [interface org.xwiki.rendering.parser.ResourceReferenceParser] hint = [link]]
        at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:401)
        at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:190)
        at org.xwiki.component.embed.EmbeddableComponentManager.getDependencyInstance(EmbeddableComponentManager.java:363)
        at org.xwiki.component.embed.EmbeddableComponentManager.createInstance(EmbeddableComponentManager.java:312)
        at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:424)
        at org.xwiki.component.embed.EmbeddableComponentManager.getComponentInstance(EmbeddableComponentManager.java:392)
        ... 3 more

This is weird since the component that cannot be found is located in xwiki-rendering-api which you should get transitively. Try adding it:

    <dependency>
      <groupId>org.xwiki.rendering</groupId>
      <artifactId>xwiki-rendering-api</artifactId>
      <version>...version here...</version>
    </dependency>

Still the same error. Running the class from eclipse works fine, however the error happens when running the packaged jar from the terminal.

I’ve also added all the jars from Index of /releases/org/xwiki/rendering/xwiki-rendering-standalone/9.6 into my Ant project’s library and packaged into the jar. Still similar problem. Running it from eclipse works fine, but not from the jar. I guess it might be a dependency issue, but can’t figure out what’s missing as every jar has been added.

The only reason you’re getting this error is because you have the wrong classpath for some reason and the xwiki-rendering-api JAR (or xwiki-rendering-legacy-api-9.6 which wraps it and add some legacy APIs on top of it) is not in your classpath. You should check your CP.

That was it! I added two things:

  • <addClasspath>true</addClasspath> in my maven jar plugin,
  • Added a maven dependency plugin to copy all dependency jars to my target directory.

Currently works when running it from the jar, but requires all dependency plugins to be in classpath outside the jar (so the fat jar isn’t working yet).