Fast Swap in WebLogic 10.3 (and JDeveloper 11g) – redeploy after compile in running application

 

One of the cool new things I learned about here at the ODTUG 2009 conference is the fast swap feature in WebLogic Server 10.3 and above. So far, Application Server features have had limit use in my little development world, but this is one that may have quite some value for me, as I am developing my web applications in JDeveloper and constantly deploying, running and testing them. This feature will considerably shorten those development cycles!

The fast swap feature makes it possible to have classes that are changed and recompiled in JDeveloper immediately redeployed on WLS, without actually redeploying the entire application. By setting a single configuration option in a configuration file and configuring the output path for the compiler in JDeveloper I can shorten most of the development-compile-deploy-test cycles by eliminating the deploy (and application restart) step.

Note that there are some (minor) limitations to the type of changes that can be hot swapped. Also note that the fast swap only applies to class files – and not to one of the many XML files that are part of most web applications today. The fast swap has already been available much longer in the case the application was running in Debug mode (also known as hot redeploy). However, this type of hot redeploy is much more restrictive with regard to the code changes it will accept (only changes within methods).

So how does it work?

The simplest steps to see this feature in action are the following:

1. Start JDeveloper 11g

2. Create a new Web Application

3. Create a Servlet

Have the Servlet return some value

4. Configure the <fast-swap>  element in the weblogic.xml file:

* from the ViewController project node in the application navigator select the menu option New; select the General, Deployment Descriptors category and select on the right hand side the WebLogic Deployment Descriptor item.

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap createdeploymentdescrp1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

* in the wizard that appears, select the option weblogic.xml and click Finish

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap createdeploymentdescrp2

* in the weblog.xml file that is now added to the project, add the following XML fragment:

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

 

 

 

 

 

 

 

 

 

5. Run the Servlet (which will compile the application, start WLS, deploy the application and start the browser with the URL where the application (servlet) can be accessed

See the result appearing in the browser

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap runservlet

6. WebLogic Server will only be able to spot changed class files in the deployment directory where the web application has been exploded. You will have to locate the system11.1.1.0.31.51.56\o.j2ee\drs directory (the exact number sequence after system can vary with the exact version you are using); in that directory, you will find a directory that is named as your web application is, and inside that directory there is a webapp directory that contains WEB-INF with a classes subdirectory. That classes directory (in my case that is system11.1.1.0.31.51.56\o.j2ee\drs\WLSFastSwap\WLSFastSwap-ViewController-webapp\WEB-INF\classes) is where during deployment the application’s classes were deployed to and that is where WebLogic will check for hot swappable classes.

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application

Now that you know the location of your (deployed) classes, change the Project Output Path for your ViewController project. From the context menu on the project, select Project Properties. Select the Project Source Paths node. On the bottom of the page that opens, you can set the Output Directory. Set it to the <long name>\WEB-INF\classes directory you discovered just before. Now any class gets compiled into that directory where it can be detected by WebLogic Server.

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application

7. Change the result returned from the Servlet

Make some changes to the code in the Servlet Class to make it return a different value than before. Note: the fast swap not only applies to the Servlet Class but to any class that is deployed in your application.

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap sourcechangedservlet

8. Compile the Servlet

You may check whether the compiled class is written to the ‘exploded deployed’ classes directory. If you can see it appearing there, then so can WebLogic Server.

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap changedservlet inclasses

9. Refresh the browser => the new output is visible, even though we did not redeploy the web application

 

Fast Swap in WebLogic 10.3 (and JDeveloper 11g) - redeploy after compile in running application fastswap changedservlet

 

Note: there are some limitations for the changes that fast swap will support.

Resources

Documentation on WebLogic Server 10.3 – Fast Swap

6 Comments

  1. Asmit June 3, 2011
  2. lwpro2 December 9, 2010
  3. Florin POP January 20, 2010
  4. Kenton Ho July 2, 2009
  5. George Maggessy June 29, 2009
  6. Jean-Philippe Melanson June 29, 2009