Development and debugging with JRebel and IntelliJ IDEA

Setup

Mac setup

JRebel setup

jrebel.tar

rebel.xml

Additional Tomcat setup

Install IntelliJ IDEA

IntelliJ IDEA settings

Care and feeding of Tomcat

Setup TOMCAT_HOME

Mac:

export TOMCAT_HOME=/Library/Tomcat/Home

Linux, if following directory pattern from Amazon EC2 setup example

export TOMCAT_HOME=/opt/tomcat/home
Shutdown Tomcat

Before trying to shutdown Tomcat, make sure the IntelliJ IDEA debugger doesn't have the process broken at a breakpoint.  If it does, quit the debugger.

Issue the shutdown command:

 cd $TOMCAT_HOME
./bin/shutdown.sh

Make sure it's really dead:

 ps auwwx | grep java

Look for processes with args relating to Tomcat.  If you see one, try to kill the process, ps again, etc.  If it still won't die, do kill -9.

Start Tomcat with JRebel and jpda debugging

Before issuing the Tomcat start command, make sure it is really not running.  If it is running, issue a shutdown/kill until it succumbs (see above).

Start a terminal to watch for monitoring the logs during startup (if this is the first time you're starting Tomcat you'll need to do this after startup since the log won't yet exist):

 tail -f $TOMCAT_HOME/logs/catalina.out

Issue the start request:

 cd $TOMCAT_HOME
./bin/catalina-jrebel.sh jpda start 

It will spew out lots of startup messages to the log, which should end with a message of the form:

  INFO: Server startup in 198652 ms

Now you should be good to go to http://localhost:8080/ and either login or register for an account.

Managing Modifications/Builds

Assuming you have JRebel working and properly integrated, different types of changes lead to different required actions to be properly reflected.  Changes made either through editing in IntelliJ IDEA or pulled from git are, as far as I know, equivalent for these purposes.

It helps if during development you disable the browser cache.  In chrome you do this via the following steps:

  • View -> Developer -> Javascript Console
  • Click on the gear in the lower right corner
  • Under Network, check Disable cache

When changes are made, follow the lowest bullet that corresponds to the new set of changes:

  • edit a javascript or jsp file: you should just be able to do reload page in the browser to get the changes.  Sometimes you may need to also clear the cache.  
  • edit a java file: When you have changed a java file you will need to build before JRebel picks up on the changes.  You'll find it under the Build -> Make Project menu.  If you're using the default key bindings, it's CTRL-F9.  If you're using Chris' settings (see Notes about IntelliJ IDEAuse Ctrl-M.  Do reload page in the browser.
  • edit a .properties file or add a directory: JRebel does not pick up on these types of changes properly.  Do the Tomcat restart dance: Shutdown Tomcat, go to the command line, cd fluxtream-app, do 'mvn clean install', and restart Tomcat (see below).  After that's done, login at http://localhost:8080/

    cd $TOMCAT_HOME
    ./bin/shutdown.sh
     
    cd ~/projects/fluxtream-app
    mvn clean install 
     
    cd $TOMCAT_HOME
    ./bin/catalina-jrebel.sh jpda start
     
  • add/modify a connector: This includes both code changes and changes to connector pictures.  Do the Tomcat restart dance as described above.  

Connector debugging

It helps to be able to use the admin console to be able to debug connectors.  Here are the steps:

First, you need to make yourself an admin in your local flx DB.  This assumes you're user ID 1; modify the 1 to some other number to affect a different user:

 mysql -u root flx
select * from Guest;
update Guest set roles = 'ROLE_USER,ROLE_ADMIN' where id=1;

In IntelliJ, open the Updater.java file specific to the connector you're debugging (example: FitBitTSUpdater.java for the Fitbit connector) and put a breakpoint in the updateDataHistory method.

If not already debugging, select  and click the debug start button: (see the Setup for debugging section of Notes about IntelliJ IDEA for how to set up to debug on jpda 9000).

Now go the the connector admin console at http://localhost:8080/admin/1

Find the name of the connector you want to debug and click the button that looks something like this .  The exact text will depend on the types of facets in use by that particular connector.

That should hopefully hit your breakpoint.