Thursday, August 22, 2013

JRebel, Intellij, and maven placeholders - lessons learned

In my last post I have mentioned that there are some scenarios where using JRebel is not so straightforward. But it does not mean it's complicated. There are three steps needed: think, configure, and run. For those of you who need some sandbox for experimentation there is trivial project deployed to GitHub. There are several revisions that will illustrate the problems and solutions I am discussing.

Think

The rule of thumb (in my opinion) is to work with the smallest deltas possible. Unfortunately, there are different conditions for capturing changes for different types of resources. Fortunately, we can handle most (if not all) of them.
The rebel configuration generated by the IDE plugin maps jar/war/ear config to default location. In case of jars, it is the build (target) folder. I am working with Intellij but my project's layout is defined by maven. Thus incremental changes to java classes are handled easily in the default configuration. Resource (like xml or property files) changes are captured by JRebel only if we update them in the build folder which (to my best knowledge) must be handled by maven. The situation of Eclipse users with m2e plugin on board is a way better as they can configure resource processing triggers.
Alternatively we can adjust rebel.xml configuration. In this way changes are captured as soon as files are saved. But ... This mode is not applicable when we have any preprocessing in resource files.
Finally, we can map several physical locations to a virtual one. There filtering mechanisms allow us to find the most optimal configuration for our needs.

Configure

JRebel can be configured in several different ways. First, the rebel.xml file might be generated by Eclipse/Intellij plugin (from what I've seen plugin for Eclipse is more powerful). Second you may configure maven plugin to generate rebel.xml file for you. Finally, you can just write it by yourself.
In the listing below a simple JRebel configuration for single module is provided: In this configuration the classpath of mod2.jar will be replaced with the content of build directory.
If we want to have to see immediate effect of the resource changes we can use the following configuration: In the above listening we combine the class path from two locations. The resources are monitored in source folder so every change triggers reconfiguration. Classes and other types of resources are collected from build directory. Thus, classes are updated on-the-fly after the recompilation.
Please note that in the previous scenario there will be an exception thrown in case there are maven placeholders in resource files. In this case we need to slightly modify our example. This way we capture instant changes to resource files, and changes to the property file triggered by maven resource processing.

Run

This is it we have chosen and configured our application (maybe in a separate maven profile) to be run with JRebel. Run it from within your IDE, or as agent in standalone mode.
In my next post I will try to describe my observations on using JRebel for maven web modules.

JRebel is great but what to do when you application is not a "typical" one.

I find JRebel a great tool. It may save you some/a lot of time depending on your scenario. There are plugins that allows for on-the-fly reconfiguration of multiple aspects of your application. You can perform a complete makeover to you Java classes, JSP resource, IoC configuration, aspects - to name only few.
I have capture a screencast  for a very simple example. There are few beans that are dynamically reconfigured - as well as the logging configuration.

But what to do with more complex scenarios ? In the following posts (or post) I will try to share my observations on using  JRebel in a project that:

  • is developed by multiple developers (using varying tools while maven is common denominator)
  • has multi-modular structure and quite few lines of code,
  • has several builds modes (e.g. production, development, and testing artifacts with varying configurations are possible)
  • uses nasty maven tricks including resources filtering, profiles, conditional configuration, overlaying and many more,
  • allows for building different products from partially common code-base
For the moment I will tell you one thing: default configuration is not sufficient here. 

Monday, August 19, 2013

Hibernate filtering behavior with cache.

As you may know there is a possibility in hibernate to handle objects visibility with filtering rules.
There are few issues worth remembering when filtering is combined with cache mechanism:

  • the filtering is not enabled by default (so if you want to use it for a session you need to enable filters)
  • the filtering bypasses second level cache. 
  • the filtering is not applied for Session.get or Session.load methods.

Wednesday, November 23, 2011

Ubuntu: Some figures are not printed in PDF files?

It gets really annoying especially when there is no time for dealing with that. I have had this problem from time to time printing pdflatex or OOffice pdf files. Some images are not printed. The problem occurs when you have multi-layer image in your pdf (actually converting the image to pdf does not help). I must admit I don't have a time to find a core problem. Therefore, the simple solution is to flatten (merge the layers) the image. You can do it i.e. in Gimp.

Wednesday, March 23, 2011

Latex balancing last column.

I was asked to adjust my paper to the publisher's requirements. That included balancing the last page. Well, life is sometimes easier than you could expect.

Just \usepackage{flushend}.

Sunday, February 27, 2011

buying E-books: thousands reasons against DRM

I have a great device that makes my life easy and colorful (well gray is a color, isn't it ?) - BeBook Neo.
I decided to read some new books bought in polish e-store.  It should be easy ? It was not:
  1. The book have a DRM. 
  2. I am using Linux.
If you sum-up these two you can end up in hell. First, to read content which is protected you need to have an Adobe Digital Edition. As, usual there is no version for Linux. But browsing net you can find out that it should run smoothly on wine. Well, thats true as long as you are not using cross over. On cross over you can install it but the software crashes just after clicking acceptance button in ADE. After some time I have managed to install ADE using standard wine for ubuntu. Great ? Not, really.

But there is at least some progress. I am  able to download the book I've paid for. Well, I am EVEN able to read it on my linux machine. To transfer the book to my BeBook I should just plug it in and authorize with my Adobe ID. Let's try it ... result ... nothing. Maybe it works smoothly on Windows or Mac, my device is not discovered by ADE so there is no chance to transfer the book. Another try. On a BeBook site you can read that to read DRM content the newest firmware is needed. Downloading...Copying...Restarting... Reconnecting... and ... no change. 

So why not to just get rid of DRM ? If you're interested how to do so, you can google for the answers or just jump there. There was slight modification needed in my case. 
  1. To run the ineptkey.pyw I had to use windows version of the Python and PyCrypto lib.
  2. To get rid of the DRM I needed to run the cli version of the ineptepub.pyw script using linux version of python (with windows version there was an access error : IOError: [Errno 13] Permission denied)
To sum-up I have spent thousands of seconds to be able to read my book on my eBook device.  I don't want to install Windows only to be able to read my books. But thanks to Adobe great ideas I almost have to do so. 

If you know any easier way to read your books on BeBook I would like to hear from you. 

Monday, February 21, 2011

CNF goes RAP.

I am glad to announce that Common Navigation Framework is ported to RAP. Thanks to the effort of CNF it was not so difficult.
There is a lot publish on CNF, so if you want to know how to start with CNF you can go here or there.
Framework is really useful and now ready to be used in webapps.

Anyway I decided to show a short example. So here it is.

There are two content providers that contribute to the tree. One providing a real nodes, second providing "virtual" ones. To put CNF online and still keep it single-sourced is good to separate the RAP application logic from the view contribution.





Then our contribution navigations should be marked optional (org.eclipse.ui, org.eclipse.ui.navigator, org.eclipse.ui.rap, and org.eclipse.rap.ui.navigator).  The dependency is resolved at the run-time for both RAP and RCP configuration.

This example can be downloaded as zip archive which contains two bundles and starting configuration
The starters for RAP and RCP configurations are attached in the examples.
Oh... And the last important thing:


The CNF port project page is maintained at Eclipse Wiki.
So you can find a link to CVS sources there :)