Sunday, March 3, 2013

Upgrading the Version Of Dojo Used By Roo

As of version 1.2.1 of Spring Roo the version of Dojo that comes packaged in the Javascript resources JAR (spring-js-resources-2.2.1-RELEASE.jar) is 1.5.  The current production version of Dojo is 1.8 with the earliest version being supported by that team is 1.6., while version 1.5 has been sunset.  

The Dojo toolkit beginning with version 1.7 adopted the use of the CommonJS Asynchronous Module Definition framework work for loading the various modules resulting in a significant rewrite of the library.  With that and other changes in architecture the Dojo the current version, 1.8, is significantly different then that of version 1.5.  While the folks involved in the Dojo project have maintained backwards compatibility to support version 1.0 architecture.  They have also made it clear that beginning with version 2.0 that support will be removed.  

So any project that involves significant modifications to the web tier should probably upgrade the version of Dojo.  Since any development that involves Dojo should be written against the new API.

Normally to upgrade Dojo one would;
  • Download the latest version of Dojo from http://dojotoolkit.org/download/. 
  • Unpack the contents of the distribution into a folder under the resources folder. 
  • Modify the mvc:resources definition in the webmvc-config to use the new distribution.
For example in the folder /src/main/resources/META-INF the dojo-release.1.8.3 distribution was added.  So the new Dojo release can be found at /META-INF/dojo-release-1.8.3 on the applications classpath.
Once the new implementation is available to the application we need to modify the webmvc-config.xml file, adding the folder containing the newly installed Dojo installation.  It is essential that the entry for the new Dojo installation is before the classpath:/META-INF/web-resources/ entry.  So the mvc:resources definition should now look something like;

<mvc:resources location="/, 
 classpath:/META-INF/dojo-release-1.8.3/, 
 classpath:/META-INF/web-resources/" 
 mapping="/resources/**">


This is when troubles in paradise begin.  The problem with this method is that the Dojo implementation is in a folder that Spring Roo is monitoring for changes.  With the Dojo implementation being rather sizable, having over eight thousand files, monitoring all these files really slows down Roo’s shell responsiveness to a crawl.  Basically rendering all the background behind the scenes magic that Roo provides non-functional.

Instead a better strategy is to package up the implementation Dojo into a JAR and then include that JAR as a dependency to the Roo project.  Now the Dojo implementation files are outside of the project folders being monitored by Roo, but available the class path.  To  upgrade Dojo using this method we need to;
  • Create a Maven project that builds a JAR file.
  • Create a META-INF folder in the project.
  • Copy the Dojo implementation into a META-INF folder.
  • Run the Maven project to package and install the resulting JAR.
  • Add a dependency to the newly created JAR to the Roo project.
  • Modify the mvc:resources definition in the webmvc-config to use the new distribution.
The maven project to build the JAR file is quite simple.  First a simple maven project is created to setup the basic maven project file structure.  
<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.repik.roo</groupId>
 <artifactId>dojo-js</artifactId>
 <version>1.8.3</version>
</project>
Then in the src/main/resources a META-INF folder is created and the new Dojo installation is copied into that folder.
Running Maven on the project with the goal of install will build the JAR and place it in the local repository.   Next the dependency to the new created JAR is added to the Roo web application pom.xml;
<dependency>
 <groupId>com.repik.roo</groupId>
 <artifactId>dojo-js</artifactId>
 <version>1.8.3</version>
</dependency>

And finally to make the new implementation is available to the application we need to modify the webmvc-config.xml file as we did with the earlier scheme.  Adding the classpath folder containing the newly installed Dojo installation.  It is essential that the entry for the new Dojo installation is before the classpath:/META-INF/web-resources/ entry.  So the mvc:resources definition should now look like;
<mvc:resources location="/, 
 classpath:/META-INF/dojo-release-1.8.3/, 
 classpath:/META-INF/web-resources/" 
 mapping="/resources/**">

Now the installation is complete and the new version of Dojo is available for development in the Roo web application and the Roo shell is once again functional.

5 comments:

  1. Very clear and pertinent article - thanks for posting. I have tried several times to add a new version of dojo as a folder under resources and it brought STS to a crawl and I would have to back out.

    This definitely seems to be the better approach but I can't seem to get my project to pickup the new version. The jar gets loaded into WEB-INF/lib and I've updated mvc:resources but I still get the 1.5 version. Do I need to change the load-scripts?

    ReplyDelete
    Replies
    1. I would check the order of the locations in the mvc:resources location attribute is important since this method shadows the original out of the box version.

      I would also check that the class path specified in the location attribute matches that of the assembled jar. It's these kinds of the things I usually mess up.

      Delete
  2. Thank you for posting. I followed closely but stuck on one problem for days, finally I solved it minutes ago, so just want to share this. Basically, I couldn`t load the new dojo, because the jar wasn`t copied to server when deploy. I had to goto `Deployment Assembly` from spring tool suite (eclipse), add the jar dojo-js-1.9.1.jar manually, path set to \WEB-INF\lib. Now it works.

    ReplyDelete
  3. I've intergrated dojo 1.9.1 in our Spring roo project, i've only uncomressed the downloaded dojo version into the folder src/main/resources/web-resources/dojo.1.9.1
    don't need to modify webmvc-config.xml


    BUT THE PROBLEM IS:
    The files Spring.js and Spring.dojo.js (of spring.js.resources.jar) use the old version dojo (major:0, minor: 0)
    and we can't load two version of dojo in the same project.

    ReplyDelete
    Replies
    1. Hi James, did you find any way out of this, this is actually the problem why we are not able to use the new version. Some of the spring validation etc. fails then

      Delete