Find it hard to create a xwiki component in java, eclipse

I have followed the steps to create a maven project with the archetype from this page http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents. Now I want to make changes following this page http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent%20Module. The java files from the second link are for a Maven project or this is a different approach?

You are actually following two completely different things.

http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent%20Module is about implementing a component in a wiki page which is not want you want here if you started with the archetype. The Java part you can see in that page explain you how to write a bridge which convert a wiki page into a Java component, not to implement a component for an existing role.

http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents has all you need to create a Java component but it would be easier to direct you to the right documentation if you could tell us which kind of component you want to implement exactly. The documentation you found gives you the basic and the rest is documented in each specific module.

We have 4 teams, each team has to do a module of the final application. We want to do in xwiki the frontend part (velocity, html, javascript) and the work with classes and objects in java. Now, all I want is to create a simple app like the basic project from the 2nd link just to see how it works.

I have created the maven project helloworld, then I moved the jar in XWiki\webapps\xwiki\WEB-INF\lib. I am stucked at how to call the service, I wrote $services.hello in a wiki page in wiki edit mode and it doesn’t give me anything but $services.hello.

When you want to insert Velocity code in a wiki page you need to use {{velocity}} macro as in:

{{velocity}}
$services.hello
{{/velocity}}

Same thing for any other script language (you have groovy macro, python macro, etc.).

Have you followed http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HFromwikipages ?

I wrote

{{velocity}}
services.hello.greet()
$services.hello
$services
{{/velocity}}

It looks like it doesn’t find my service.

And this is what I have in eclipse

$services API is dealing with script services so in your screenshot it should be HelloWorldScriptService, not HelloWorld.

If it does not find it there is two possibilities:

I tried again to make a project from that archetype.
The project has all it needs from the archetype. It has the file components.txt and inside is com.acme.internal.DefaultHelloWorld com.acme.script.HelloWorldScriptService

I call the service with $services.hello because in HelloWorldScripService is : @Named("hello")

In log was just this warning:

WARN iComponentManagerEventListener - Failed to register the wiki component located in the document [xwiki:XWiki.ComponentClass]: WikiComponentRuntimeException: You need to add an Object of type [XWiki.ComponentMethodClass] in document [xwiki:XWiki.ComponentClass] to implement method [org.xwiki.observation.EventListener.getName]

I don’t think it has something to do with my service

Did you restarted XWiki after putting the JAR in WEB-INF/lib ?

Yes, I restarted it.
Last night I tried on my 2nd computer and the same thing happened .

One of my colleagues did the simple probject in intellij and he succeded. I think in eclipse didn’t work because it didn’t have all dependencies.
Anyway thank you for your patience :smile:.

1 Like