JRebel Tutorial: Using JRebel in Eclipse with Google App Engine and GWT
In this tutorial you will learn how to install, configure and use JRebel in Eclipse with Google App Engine and GWT.
- Sample Project: StockWatcher
- JRebel in Action
- Install the proper version of the Google Plugin and GWT Tooling for your version of Eclipse through the Eclipse Marketplace.
- Open up your Eclipse Marketplace. JRebel should be listed in the Featured section, but if you don’t see it type “jrebel” in the search box.
- Click Install.
- Navigate through the rest of the installation instructions.
- Read and agree to the license agreement.
Once the installation is complete, restart the IDE in order for the changes to take effect.
After you restart the IDE, if you do now have JRebel license yet, the plugin will notify you about this sad fact and ask for registration. Click on the link in the red pop-up and proceed with the license setup.
Please see the reference manual
for the license activation options.
Sample Project: StockWatcher
You can install the sample StockWatcher application using this link:
After installing the zip file, extract the contents to the location of your choice and navigate back into Eclipse. In your Eclipse toolbar, you should see a small circular Google icon – click it and select “Import App Engine Sample Apps…” in the drop down menu. In the “Select root directory:” navigate to the location of your new StockWatcher directory.
Apply JRebel Configuration to Project
To configure project to work with JRebel:
- Open JRebel Config Center (Help -> JRebel Config Center)
- Click on the box next to StockWatcher to add JRebel nature
Adding JRebel nature to the project will automatically generate
configuration file and add it to the project. See reference manual for more information about the configuration file.
You can also configure JRebel to work with the project by right clicking on the project itself, scrolling down to the JRebel tab and clicking “Add JRebel Nature”.
Now that your application is configured, you need to configure your server. The easiest way to do this is to just run your application.
- Right click on your project and select Run As -> Web Application in the drop down menu.
- Click “Launch with JRebel Agent” when the following pop-up appears.
JRebel in Action
One you start the server with JRebel agent enabled, you should see JRebel specific messages:
This is the JRebel Welcome Banner. It details the version of JRebel you are currently using, whether there is an update, the kind of license you are using, how long until it expires, disabled plugins etc.
You will also see JRebel log messages showing what specific directories JRebel is monitoring, listed in
Now let’s make some changes!
This is the unmodified home screen of the StockWatcher application. I added the “A” stock. As you can see, the table currently displays the Symbol, Price, Change, and a Remove button.
Adding a new working column (1a and 1b):
Adding the Number of Changes column (1a):
- Open the StockWatcher.java file (this is where we will be making all of our changes).
- Add “stocksFlexTable.setText(0, 4, “Number of Changes”);” to the onModuleLoad() method.
- Add “stocksFlexTable.getCellFormatter().addStyleName(0, 4, “watchLIstNumericColumn”); to the onModuleLoad() method.
- Add “stocksFlexTable.getCellFormatter().addStyleName(row, 4, “watchListNumericColumn);” to the onModuleLoad() method.
- Save and you should see the following in your log file. This is JRebel reloading the StockWatcher classes.
- Refresh the browser and you should see our new Number of Changes column appear:
- Now add the “A” stock again and you should see that while we do have the new Number of Changes column, it is empty:
Populating the Number of Changes column with a counter (1b):
We have our column, now let’s populate it with a counter! Every time the price updates we want the counter to increase by 1 for each stock.
- Add the “private ArrayList counter = new ArrayList();” field to the StockWatcher.java class.
- This new field will keep track of the counter for each Stock.
- Add “counter.add(0);” to the addStock() method.
- Starts the counter at 0 for each Stock.
- In the onClick(ClickEvent event) event handler in the addStock() method, add counter.remove(removedIndex).
- Removes the counter associated with each removed Stock.
- In the updateTable(StockPrice prices) method:
- Add “int temp = counter.get(i);”
- Add “int temp = counter.get(i);”
- Add “temp++;”
- Add “counter.set(i, temp);”
- Adds one to the current counter for each Stock
- Replace the current “updateTable(prices[i])” method call with “updateTable(prices[i], temp);”
- Passes the Stock and counter for each Stock to the updateTable(StockPrice price) method.
- Add the “Integer counter“ parameter to the updateTable(StockPrice price) method so it reads as updateTable(StockPrice price, Integer counter).
- In the updateTable(StockPrice price, Integer counter) method:
- Add “String changeCounter = NumberFormat.getFormat(“###”).format(counter);”
- Add “stocksFlexTable.setText(row, 4, changeCounter);”
- Formats the counter text properly.
- Save and refresh the browser.
- Now add the “A” stock again and you’ll see that our new counter is working properly!
Adding a separate remove button (2):
- First let’s add the necessary fields to create our text box and the new Remove button:
- Add “private HorizontalPanel addRemovePanel = new HorizontalPanel();”
- Add “private TextBox removeSymbolTextBox = new TextBox();”
- Add “private Button removeStockButton = new Button(“Remove”);”
- To assemble the new panel in the onModuleLoad() method:
- Add “addRemovePanel.add(removeSymbolTextBox);”
- Add “addRemovePanel.add(removeStockButton);”
- Add “addRemovePanel.addStyleName(“addPanel”);”
- In the onModuleLoad() method add “mainPanel.add(addRemovePanel);”
- Adds the new panel to the main panel.
- Add a clickHandler to the onModuleLoad() method:
- Removes the Stock inputted in the Text Box.
- Save and the following will appear in the log:
- Refresh your application and add “A”, “B” and “C” Stocks.
- Now type “B” into the remove Text Box and click the Remove button: