Creating a sitemap.xml for a subwiki


I am trying to generate a sitemap.xml file for my XWiki. Well, more specifically, for a sub wiki on that wiki farm.

I’ve created code (velocity) before to dynamically list pages and other tasks, so that part is fine (for the most part, I can prob. figure out what I need).
What I am totally new to / unsure is how to create/write to /replace (on updates) a sitemap.xml file that will be accessible externally (someone else will be building a sitemap index of a bunch of sitemaps, including mine).

Now, I’ve had a look already at the examples found here and though “yay, I’m done with example #2”… but then it does not run as-is.

I’ve only ever used Velocity (and still relatively new to it), not Groovy, so I’m not sure what to look for/fix and have been googling for a while and found nothing helpful… :expressionless:

The error I am currently getting is “Failed to execute the [groovy] macro. Cause: [startup failed: Script61.groovy: 26: expecting ‘}’, found ‘content’ @ line 26, column 15. w.println content ^ 1 error ].”. I’m using the example 2 linked above as-is with no modification (simply placed it in {{groovy}} & {{/groovy}} tags). The amount of “{” & “}” seems to match. Unsure what to fix in this script to make it run.

Also, I’ve tried just some other stuff quickly, poking around, such as:

  filename = 'sitemap.xml'
  File file = new File("out.txt")
  file.write "First line\n"
  file << "Second line\n"
  println file.text

I get the following error from it: “Failed to execute the [groovy] macro. Cause: [out.txt (Permission denied)]. Click on this message for details.”

So, all being said, I need some guidance in creating a file that will be accessible afterwards (ex: sitemap.xml) externally as a raw XML file (not an XWiki page).


First question, do you really want an external file generated or would you prefer to generate the sitemap in a wiki page (which can then be accessed remotely if needed)?

Re permission denied, well it’s because of permissions :wink: The user you’ve used to start your servlet container is not allowed to output to the current directory used to start the servlet container. You should specify a full path or change permissions.

1 Like

Thanks for the assistance!

I really do need a .xml file that is generated and accessible externally.

I cannot have the wiki page that generates the sitemap accessible externally (requirements from above :stuck_out_tongue: ).

I’ll check with my sys admin to see what can be done on that end.

That being said, would groovy examples about file management from other sources (non-XWiki) still apply to/work in XWiki properly?
If not (or with caveats), do you have any other recommendations on how to handle the file generation using Groovy?


Yes. There’s nothing special in XWiki. If you need more third-party libraries you can also install them in your wiki.

1 Like

Fixed the permissions issues by having a static file available in the root folder of the web server (tomcat8).
This file is a soft link to a location where the user running tomcat8 can safely work without compromising security in case of a breach. :wink:

Thanks for pointing out the obvious (@ permissions… lol…). Getting more tea now :smiley:

Script can now write to the file and it is visible. But the script creating page is not! Everything I wanted is completed :smiley: