Tuesday, January 7, 2014

How to add a sitemap in my Grail war application ?

Today, I decided to add a sitemap for my new Grail website.First of all, I generated one by using online sitemap generator. For example, there is the following http://www.xml-sitemaps.com . You have to put your website url and it will produce sitemaps files (xml, zip, and so on). Here is an example of sitemap :
<?xml version="1.0" encoding="UTF-8"?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->

<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/training</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/about</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/under</loc>
</url>
<url>
  <loc>http://opendoowap-totalprog.rhcloud.com/page/website</loc>
</url>
</urlset> 

Then, I download the file sitemap.xml and I paste it in the web-app directory of my Grails application.After that, I modified my BuildConfig.groovy like the following :

grails.war.copyToWebApp = { args ->
    fileset(dir:"web-app") {
        include(name: "js/**")
        include(name: "css/**")
        include(name: "fonts/**")
        include(name: "images/**")
        include(name: "WEB-INF/**")
        include(name: "sitemap.xml")
    }
}
To finish, I run grails war command and deploy it in Tomcat web container.
That's all. Now, your sitemap is available in http://your.app.com/sitemap.xml and you can add for example to google webmaster tools.