« Sample WebLogic JMX Client | Main | Managing WebLogic servers with JConsole »

Using FastSwap to speed up development

A fast turnaround time is something that most developers appreciate and since JDK 5 it is possible to redefine a class without dropping the class loader. However, the support provided by the JDK is limited and does not allow the developer to reshape the class, i.e., fields and methods cannot be changed/altered. FastSwap is a feature within WLS that, when enabled, is designed to overcome these limitations. For example, it will allow the developer to add new methods to an already loaded class and see those changes take effect immediately.

Enabling FastSwap

In order to take advantage of FastSwap, WLS must be running in development mode and FastSwap must have been turned on for that particular deployment. For applications deployed as an EAR, adding the element to the weblogic-application.xml file enables FastSwap and for applications deployed as a WAR, the element should be inserted into the weblogic.xml file instead.

  <fast-swap>
    <enabled>true</enabled>
  </fast-swap>

FastSwap will only monitor changes of classes in exploded directories so if an exploded EAR contains an archived WAR, any changes to that WAR will not be detected. Therefore, the WAR also needs to be unpacked and then FastSwap will monitor all the classes found under the web application's WEB-INF/classes directory. Note that any jars residing in WEB-INF/lib will not be monitored.

Developing with FastSwap

Once FastSwap has been enabled for a particular deployment, it will pick up any change made to a monitored class at runtime, allowing the change to take place immediately.

Using a web application as an example, the typical development flow would be:


  • Deploy the exploded web application

  • Access the application through a web browser

  • Modify the code, compile the changes and have the corresponding class files saved to the correct location under the exploded application.

  • Access the application through a web browser once again, and your changes will now have been applied and should be visible.

Note that FastSwap will not redefine any classes as soon as they have changed on the file system. The reason is because a change to one class file can affect other classes (e.g. when a method signature is changed) so all classes must be redefined at the same time. Therefore, the developer will need to tell FastSwap when it should start its operation. For web applications, this is accomplished by going through a servlet but for other applications the developer has to use the JMX interface for FastSwap. However, there is an Ant task accessing this JMX interface that can used to trigger FastSwap, as shown in the below example.

<project name='MyProject' default='all'>
  <taskdef name='fast-swap' classname='com.bea.wls.redef.ant.FastSwapTask'/>
  <target name='all'>
    <fast-swap
      adminUrl='t3://localhost:7001'
      user='weblogic'
      password='weblogic'
      server='myserver'
      application='SimpleApp'
    />
  </target>
</project>

Where the parameters are:


  • adminUrl: connection url

  • user: user name

  • password: user password

  • server: managed server name

  • application: deployed application name

Limitations & Further Reading

Even though FastSwap is an improvement over the default support found in the JDK there are still some limitations to what it can accomplish. For a list of these limitations as well as more information regarding FastSwap, please visit the following link:

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/deployment/deployunits.html#wp1053872

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mt/mt-tb.cgi/14415

Post a comment

About This Entry

This page contains a single entry from the blog posted on October 3, 2009 11:55 AM.

The previous post in this blog was Sample WebLogic JMX Client.

The next post in this blog is Managing WebLogic servers with JConsole.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle