This may not be a bug/issue/problem.
I sought to generate a site map-with-index per the example in the documentation
Example code from documentation: WebSitemapGenerator wsg = new WebSitemapGenerator("http://www.example.com", myDir); for (int i = 0; i < 60000; i++) wsg.addUrl("http://www.example.com/doc"+i+".html"); wsg.write(); wsg.writeSitemapsWithIndex(); // generate the sitemap_index.xml
What steps will reproduce the problem? 1. Instantiate WebSiteMapGenerator 2. add urls 3. call wsg.write() 4. call wsg.writeSiteMapWithIndex()
Expected Result
Code generates sitemap.xml and site map index xml file.
Actual Results
Exception while exeecuting task 'Generate Site Map' (999) java.lang.RuntimeException: No URLs added, sitemap index would be empty; you must add some URLs with addUrls
Issue: -I don't see a place where the api requires/allows you to 'add a url' between the write() and the wsg.writeSitemapsWithIndex();
-I have a very small data set: one url. This does not seem relevant to the problem.
Version
Version 1.0.1
Appendix A. Code
WebSitemapGenerator wsg = new WebSitemapGenerator(BASE_URL, myDir);
for (Post post : posts)
{
ChangeFreq changeFreq = ChangeFreq.HOURLY;
WebSitemapUrl url = new WebSitemapUrl.Options(BASE_URL + ELEMENT_URL + post.getID())
.lastMod(post.getThreadActivityDate())
.priority(1.0)
.changeFreq(changeFreq).build();
wsg.addUrl(url);
}
wsg.write();
wsg.writeSitemapsWithIndex();
Comment #1
Posted on Jul 13, 2010 by Massive WombatA follow-up:
I believe the error occurs in the following situation: a) Use the default constructor: WebSitemapGenerator wsg = new WebSitemapGenerator(BASE_URL, myDir);
b) number total urls < maxUrls per file (e.g. 6 vs. 50000)
I worked around the situation by doing the following: * using the 'builder' method for constructing SiteMapGenerator options. * specify a low value for the 'maxUrls' (e.g. 2)
Result: The Library generated correctly site map and site map index xml files .
Comment #2
Posted on Feb 16, 2011 by Swift LionMe too! I found the max value for 'maxUrls' is 231.
Comment #3
Posted on May 6, 2011 by Happy CamelI will say it is a bug as nothing says that it can't exist a sitemapIndex if only one sitemap file has been generated. As a fix, I propose the following patch.
Comment #4
Posted on Feb 27, 2012 by Massive MonkeyComment deleted
Comment #5
Posted on Jul 30, 2014 by Massive Lionhow to apply patch
Comment #6
Posted on Mar 20, 2015 by Helpful BirdThis has been fixed in sitemapgen4j v1.0.2 (now hostet on github: https://github.com/dfabulich/sitemapgen4j)
Status: New
Labels:
Type-Defect
Priority-Medium