Export XWiki XAR packages to Markdown, with optional sync to Confluence (including attachments).
Confluence 7.4.9 XWiki Jetty HSQLDB 15.4
- Input dir example:
xwiki/ - Data is read-only (tool never modifies original files)
- The directory contains exported
.xarfiles
Requires JDK 11+ (Java HttpClient is used for Confluence sync).
javac -encoding UTF-8 XwikiXarExporter.java- Default output directory:
out - Example (input is a directory — recursively scans
.xarfiles):java XwikiXarExporter --input "xwiki" --output out - Optional flags:
--format markdown|raw(defaultmarkdown;rawoutputs original XWiki syntax)--include-preferences(by defaultWebPreferences.xmlis skipped)--only-entry <entry>(export a single page/entry — useful for quick testing)
- Find the target page's entry name inside the XAR (typically
.../WebHome.xml):jar tf <your.xar> | grep WebHome.xml | head
- Export only that entry:
java XwikiXarExporter --input <your.xar> --output out --only-entry "<Space>/<Page>/WebHome.xml"
- Check the output:
out/<xar-basename>/<Space>/<Page>/index.md
Enable sync by providing the following flags:
--confluence-url <url>--space <space>--user <user>--password <apiToken>--dry-run(optional — prints intended create/update/upload operations without making HTTP requests)
Example:
java XwikiXarExporter --input "xwiki" --output out \
--confluence-url <url> --space <space> --ancestor <parentId> \
--user <user> --password <token>Notes:
--ancestoris optional; if omitted, pages are created at the Space root
Useful when an export has already been run and out/... contains pages.csv, per-page index.md, and attachment files.
Example (upload a single export directory):
java XwikiXarExporter --upload-from out/<xar-basename> \
--confluence-url <url> --space <space> \
--user <user> --password <token>Example (upload the entire out root — automatically scans subdirectories containing pages.csv):
java XwikiXarExporter --upload-from out \
--confluence-url <url> --space <space> \
--user <user> --password <token>- XAR files may contain attachments: attachment content is typically embedded as base64 inside the page XML under
<attachment><content>. Runningjar tfdoes not always reveal standalone.png/.docxfiles. - The tool automatically extracts inline attachments from page XML into the page directory, then uploads them to Confluence after the page is created.
- If the Markdown references
image:xxx.png/attach:xxx.extbut the attachment is not embedded in the XAR, you can provide an external XWiki attachments directory:java XwikiXarExporter --input "xwiki" --output out \ --attachments-dir <xwiki-attachments-root>
Expected attachments directory structure:
<attachments-dir>/<space>/<page>/<filename.ext>
--confluence-urlformat:https://your-confluence.example.com