Create Sitemap Using Java
Keywords : Java Sitemap Example, Java Sitemap Generator, How To Use Sitemap Using Java, Java Code To Generate Sitemap, sitemapgen4j example,Create Sitemap Using Java Tutorial describes about How to create sitemap in java
It will also support for google site map updations
Sitemap is an easy manner for a webmasters to notify search engine spiders about pages on their sites that are accessible for crawling and indexed.
Sitemap is a simple XML file that consists of list of Entries (URLs) of a website along with some other details about URL like URL last updated time, how often URL updated ( ie; change frequency of URL) and how vital it is ( ie; priority of URL)
so that by using these informations search engines spiders can able to crawl the site.
Tools Needed For This Example
Features Of SitemapGen4j
SitemapGen4j is a java sitemap generator library useful to generate XML sitemaps in Java programming language.
By using SitemapGen4j you can able to add any number of URL's, can get gzipped output, can set lastmodified option, can set priority option, can set changefreq, can configure the date format, can validate sitemap with XML Schema Definition (XSD)
Create Sitemap Using SitemapGen4j
import java.net.MalformedURLException;
import java.util.Date;
import com.redfin.sitemapgenerator.ChangeFreq;
import com.redfin.sitemapgenerator.WebSitemapGenerator;
import com.redfin.sitemapgenerator.WebSitemapUrl;
// Java Code To Generate Sitemap
public class SitemapGeneratorExample {
public static void main(String[] args) throws MalformedURLException {
// If you need gzipped output
WebSitemapGenerator sitemapGenerator = WebSitemapGenerator
.builder("http://www.javatips.net", new File("C:\\sitemap"))
.gzip(true).build();
WebSitemapUrl sitemapUrl = new WebSitemapUrl.Options(
"http://www.javatips.net/blog/2011/08/findbugs-in-eclipse-java-tutorial")
.lastMod(new Date()).priority(1.0)
.changeFreq(ChangeFreq.HOURLY).build();
// this will configure the URL with lastmod=now, priority=1.0,
// changefreq=hourly
// You can add any number of urls here
sitemapGenerator.addUrl(sitemapUrl);
sitemapGenerator
.addUrl("http://www.javatips.net/blog/2011/09/create-sitemap-using-java");
sitemapGenerator.write();
}
}
output

|
|