Wednesday, January 15, 2014

How to deploy a web application outside Tomcat and use JRebel to prevent restarts to see the code changes

There are 2 things I feel are slowing me down while building java applications. And 1st one is copying the web applications into webapps folder of the Tomcat.After I make changes to the java code I have to compile the code, make the war file and deploy it in the webapps folder of Tomcat. This slows down the development process and java developers just wish they can avoid this. There are couple of ways to avoid this.

Deploying web application outside the Tomcat WebApps folder


One of the way is to deploy the war outside the webapp of the Tomcat which is described below.

Move to the following location in your Tomcat installation folder.

<Tomcat Home>--> conf --> Catalina --> localhost

In this folder create a xml with the name of your web application.Say I want my service to be 'MyApp1' then create a 'MyApp1.xml' in the above path.

Add the below content in the file created.

<Context path="/MyApp1" docBase="C:\Users\vkiran\Desktop\MyApp1\war" reloadable="true">
</Context>

Your are defining the  context name for your application and providing a location which has your compiled web application for the Tomcat to load. When you start the Tomcat, Tomcat will load your web application 'MyApp1' from  'C:\Users\vkiran\Desktop\MyApp1\war' location. So you don't need to copy your war file to Tomcat webapp folder every time.

JRebel


But you still need to compile your code and restart Tomcat for every code change you make.Redeploying the application for every small change in the code is one of things I hate  most in Java. JRebel provides a relief from this constant recompiling mess. JRebel reloads the classes without redeploying the application and so you can view your code changes without restarting the applications.It supports most of the Java Frameworks, has plugins for all major java IDE's and is a great productivity tool for java developers. It is a paid tool and a trial version can be downloaded from here.

Download jrebel-5.5-nosetup.zip and extract the zip file.



In Tomcat --> bin folder, create a 'catalina-jrebel.bat' file with the following content.

@echo off
set JAVA_OPTS=-javaagent:[path/to/]jrebel.jar %JAVA_OPTS%
call "%~dp0\catalina.bat" %*

The jrebel.jar is available in the extracted zip file. Replace '[path/to/]' in the above script with the path to the jrebel folder on your system.

If you want to launch your Tomcat with JRebel enabled, run this catalina-jrebel.bat.

catalina-jrebel.bat run


If you configured jrebel correctly on Tomcat, you will see some thing similar on your command prompt when you start the Tomcat. Some information on where the jrebel log file goes, what is the version, statistics on the time saved using jrebel and license etc.


Also the command prompt will display the list of frameworks supported by jrebel but not used/enabled in your application and if there are any updates to jRebel.

If Tomcat is run as a service in your development environment, select 'Monitor Tomcat' from your Run --> Programs or double click on the Tomcat icon in the system tray. Then insert the below parameter in Java --> Java Options

-javaagent:[path/to/]jrebel.jar

Replace [path/to/] with the path to the jrebel folder on your system.



If you launch the Tomcat with JRebel on, you need not restart Tomcat to see your code changes. Just refresh your browser or test the functionality without restarting the application. JRebel reloads the modified classes and so you can concentrate on your code changes without getting distracted by the continuous re-deployments.

24 comments:

  1. Hello...thank you for good information...do you have a tutorial in video or youtube?thank you...

    ReplyDelete
  2. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work Webdesign bureau

    ReplyDelete
  3. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. best web development usa

    ReplyDelete
  4. Along these lines, the main genuine downside for a web improvement firm is that they are typically pricey. On the other hand, cost is relative and greater organizations like to work with greater organizations. Web Design Curriculum

    ReplyDelete
  5. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. freelance web designer peter

    ReplyDelete
  6. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. Web Designing

    ReplyDelete
  7. This is the next step beyond a freelance professional. The web design company offers the "whole show". They provide real project management and have pulled together a team of web experts to get a wider range of jobs done.Web Designer

    ReplyDelete
  8. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. Digital marketing company

    ReplyDelete
  9. PHP is very outstanding and perceived programming language for custom website advancement with its completely useful scripting language.Webdesign

    ReplyDelete
  10. If one wants to maintain good working relationships then, edifying clients are one of the wisest ways. Web designing is an essential fragment of the service-industry and thus follows the same rules. Webdesign

    ReplyDelete
  11. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. web design company lakeland

    ReplyDelete
  12. Really appreciate this wonderful post that you have provided for us. Very informatory and important blog for those who want to design and develop a website.This is such a great resource that you are providing. Thank You for sharing this tip which is very necessary in latest strategy. Web design business

    ReplyDelete
  13. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work ui vs ux

    ReplyDelete
  14. Friend, this web site might be fabolous, i just like it. design

    ReplyDelete
  15. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. ui/ux design

    ReplyDelete
  16. In order to minimize the cost of the set up, the website designer should be equipped with predefined web templates. Having this feature in your armory, you don't need to go hog-wild with the designs for the reason that you are not designing a website by tinkering.Digital Marketing Company in Singapore

    ReplyDelete
  17. Along these lines, a site page ought to be planned remembering, the client and business needs.Webdesign

    ReplyDelete
  18. Wow! This could be one of the most useful blogs we have ever come across on thesubject. Actually excellent info! I’m also an expert in this topic so I can understand your effort. web developers

    ReplyDelete
  19. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. website design

    ReplyDelete
  20. Most of the successful web designs companies and other designers emphasize that the most important factor for creating web design templates is Web Design Oxford that it should offer original content to the readers in a way that will easily assist the search engine results.

    ReplyDelete
  21. He made a site that had the scale that would have been required. smm panel

    ReplyDelete
  22. I read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. web design in Switzerland

    ReplyDelete
  23. Today, one needs to dig deep into a website and identify issues that will greatly affect how your website ranks for keywords and phrases and how your website compares with your competition. Trust Pilot Scraper

    ReplyDelete