Wednesday, September 4, 2013

JRebel and maven overlays

It was a while ago when I have posted on issues related to using JRebel with Intellij and maven. Today I would like to say few words about web applications.
Actually, I have configured JRebel for the first time because of web apps :). Well, because we couldn't use exploded wars. Can you imagine redeploying heavy war file only to check fix for something as complicated as spelling error ? Well, I couldn't. For this basic scenario default JRebel configuration for web comes in handy. What do we have here ? The classpath space of a war is mapped to target directory whereas web content to source directory. Perfect. Now, every time I save a jsp file the change is reflected on the server. Obviously, JRebel is better than that. For example spring web-mvc is supported thus you can add new mappings to the controller on the fly.

Overlays

The maven-war-plugin comes with the overlaying feature. Overlays (when over-used) are pure evil ;), but sometimes you cannot do much about it. I will try to picture the idea with very simple example. In the figure you have two projects: web1 and web2. You can download the code from Github - last update contains the changes from current post.
I have configure the overlays to merge web2 module into web1. This can be achieved with configuration listed below. The empty overlay block is this handle so points to web1 project. As a result the resources from web2 will overlay web1's resources in case there is no exclusion specified. In the figure exclusion is marked with grey spot. As you can see the resulting war contains some resources from web1 (blue spots) and web2 (red spots). The resources from web1 are these excluded in configuration or not included in web2 module. The content of target war (only jsp's for simplification) is shown in the figure on the right. There are two files from web2 module and one from the web1 module. Ugly. In fact we have hello.jsp file in both modules.You can check the content of the web page after build & deploy procedure. When you point your browser to the action that results in hello.jsp you will see the content of the file from the web2 module.
Let's try it now with JRebel. For this experiment I will use configuration from the listing above. To run the server with JRebel you need to modify the run script or provide environment property. To enable JRebel for JBoss I have modified standalone.conf.bat adding set "JAVA_OPTS=%JAVA_OPTS% -javaagent:E:\path_to_rebel\jrebel.jar" to the configuration. After server restart you will see different content under the same location. It happened because the web folder from war is mapped to source folder in web1 module.

Modifying JRebel configuration

Lets try to achieve expected behaviour. JRebel configuration allows to add multiple directories, which is presented in the listing below. Using this configuration you should see following log messages in server log: So does it work as expected ? Nope. The content of hello.jsp from web1 module is rendered. You can try to reorder dirs in rebel.xml which helps from time to time. Actually, I was not able to reproduce this problem. I though I can pinpoint the problem playing with bigger project at work but here it works in 80% of cases. Anyway, situation is better than before. Now we are able to edit page3.jsp from the second module.
Fortunately, we can be better than that and provide a configuration that is compatible (and stable) with our overlays. When we define two link blocks the ordering from xml is preserved. So in this case web block looks like that: In case, this doesn't work for some specific version of JRebel there is only one thing you can do before bursting into tears. You can use include exclude blocks to shape the final JRebel mapping.

Final note

Web overlay mechanism is evil. You need know how does it work. You need to know locations of the files and the relations (especially overwrites) between them. When it comes to JRebel ... I wish directory definition is stable and better documented.

What comes next

In case you use the source project, you've probably got some problems with the configuration. There are full paths defined which work in my configuration and not necessary in yours. Next, time when talking about JRebel + maven I will share my opinion on how to survive sharing such a project within a team.

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 :)

Tuesday, September 1, 2009

Xubuntu 9.04 + sound controls + T61

Well sometimes some things are not so obvious. At least for me.

Recently I have overcame most annoying problem with my T61 Xubuntu configuration.
This is first IBM/Lenovo hardware I've ever have to configure sounds buttons but maybe I screw up something before.

Anyway, it seams that tpb doesn't help in this case. Fortunately, I've found this blog entry. To make it simple you need to configure your XFCE keyboard shortcuts as follow:










XF86AudioLowerVolumeamixer -q set Master 3%- unmute
XF86AudioRaiseVolumeamixer -q set Master 3%+ unmute
XF86AudioMuteamixer -q set Master toggle


Yes, I know this is only solution for XFCE but more detailed configuraiton can be read under link specified above.

Monday, March 16, 2009

Time...

It was a while since I had written for the last time.
Well sorry to say but I was busy. I newer thought that meeting can consume a great part of the week. But there are positive aspect of those days.
I have several topics to come out with:

  • finalization of spring osgi vs. standard one considerations
  • GWT with spring
  • Spring Security with JSON protocol
  • JPA/Hibernate

I really regret to drift from the Eclipse centric area but hopefully I will find some time to add something to the community.

Thursday, January 22, 2009

Spring Server + Maven + Eclipse notes

I feel I am a bit more experienced than when I've started.
Last time I've mentioned about problems I've faced. Maybe it's high time to elaborate a bit about solutions.


  1. Tools:


  2. Dependencies management:
    There are two aspect to discus. Firstly that we are usually manage our dependencies using Maven (of course if we are using maven ;D ). Secondly, bundle dependencies management. Using default configuration we need to feed maven repository using maven and spring server repository using Eclipse Server Editor, which in current version seems to be not working, or provisioning mechanisms.
    This bi-declaration effect have also consequences in how it is seen by Eclipse.
    We have two declaration of the same library in build path.


    As I am using multi-module project. And have inter-module dependencies it resulted in build path error and compilation failure.


    Default configuration has also other consequence. We have to double dependencies definition or we have maven script not usable outside Eclipse tooling. What if we want to share the project? We need to toss the usr bundle catalog round the users, etc.

  3. Solutions:
      Server configuration

      Fortunately we can make our server to use maven repository structure to look for bundles. What I am using is slightly modified configuration from documentation. As OSGi enabled bundles from spring are usually
      in com.springsourceXXX packages we can reuse this information:

      "searchPaths": [
      "repository/bundles/subsystems/{name}/{bundle}.jar",
      "repository/bundles/ext/{bundle}",
      "${user.home}/.m2/repository/**/com.springsource*/**/{bundle}.jar",
      "repository/libraries/ext/{library}",
      "repository/libraries/usr/{library}"
      ]


    • Repository configuration


      Second observation is:use OSGi enabled libraries. In other case you will need to deal with inner JAR's. Which add to the management complexity IMHO.
      Most common libraries prepared to work in OSGi can be found in SpringSource maven repository:

      <repositories>
      <repository>
      <id>com.springsource.repository.bundles.release</id>
      <name>SpringSource Enterprise Bundle Repository -
      SpringSource Bundle Releases</name>
      <url>http://repository.springsource.com/maven/bundles/release</url>
      <releases>
      <updatePolicy>daily</updatePolicy>
      <checksumPolicy>ignore</checksumPolicy>
      </releases>
      </repository>
      <repository>
      <id>com.springsource.repository.bundles.external</id>
      <name>SpringSource Enterprise Bundle Repository -
      External Bundle Releases</name>
      <url>http://repository.springsource.com/maven/bundles/external</url>
      </repository>
      </repositories>

      How to find correct dependency? Easly :) SpringServer editor can lead you to repository browser (Look at the picture).

    • Independ maven build

      The last step to is to keep all dependencies in maven. Why ? Independent build.
      My solution is maybe naive but it works - Maven profiles.


      <profiles>
      <profile>
      <id>standalone</id>
      <dependencies>
      <dependency>
      <groupId>com.oracle.jdbc</groupId>
      <artifactId>com.springsource.oracle.jdbc</artifactId>
      </dependency>
      <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>com.springsource.org.apache.commons.collections</artifactId>
      <version>3.2.0</version>
      <scope>provided</scope>
      </dependency>
      <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>org.springframework.web.servlet</artifactId>
      <version>${spring.components.version}</version>
      <scope>provided</scope>
      </dependency>
      </dependencies>
      </profile>
      </profiles>


      To build project outside the only think you need to do is to eneble standalone profile.



Monday, January 19, 2009

Tools integration

Hopefully I've found support for all ideas used in our project.
Eclipse, and it is not surprising for those knowing me, as my IDE.
Maven as a project build tools (at the moment working well only as Eclipse embedded).
Maven tooling for Eclipse. Spring Server. Spring tooling and spring tooling for eclipse. Have I missed sth ? Off course there there are SVN Track and everything eclipse has to support it.
Now let me elaborate on "hopefully". I have no doubts that without Eclipse plug-ins life could be painful.
But:

  • why I have cycles in my builds (ok I am using a bit customized scripts)
  • what is the best way to share such a project (how to share server configs, how to use relative paths)
  • how to fight with the dual sources of buildpath dependencies (one from maven, second from budle dependencies) - at the moment I am testing use of standalone profile to store dependencies from OSGi configuration.


Maybe its time (if this is possible) to build set of good practices for spring + maven + eclipse integration.

Sunday, January 18, 2009

Spring Integration Testing for Web

I am building OSGi web based (partially) application. As usual when you touch new area of technology (especially new technology) it tends to be problematic.

Today problem I have faced three weeks ago. How to test web controller.
Maybe its not a problem at all (you can configure everything manually), but I really wanted to use spring support for testing.

If you're preparing a test for IoC managed components you can use this fact (if you need more information refere to spring documentation).

To build your context you can use Spring TestFramework annotations.

package com.example;

@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "classpath:/com/example/MyTest-context.xml"
@ContextConfiguration
public class MyTest {
// class body...
}

You can also specify where to look for context(s) definition(s). And at the moment you're redy to use @Autowired annotation

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/META-INF/spring/module-context.xml", "/test-context.xml"})
public class ControllerTest {
@Autowired
private Controller controller;
}

As you can see I'am using application context and test context (which is used for components normally reached via OSGi). But if we leave it this way It won't work.
The reason is that Controller needs web context and Spring test mechanism provides normal one. But there is a solution. We can provide our context loader which is able to provide required context.
@ContextConfiguration(locations = {"/META-INF/spring/module-context.xml", "/test-context.xml"}, loader = XmlWebApplicationContextLoader.class)

And here is XmlWebApplicationContextLoader:

public class XmlWebApplicationContextLoader extends
AbstractContextLoader {
...
public final ConfigurableApplicationContext loadContext(String... locations)
throws Exception {
if (logger.isDebugEnabled()) {
logger
.debug("Loading ApplicationContext for locations ["
+ StringUtils .arrayToCommaDelimitedString(locations)
+ "].");
}
GenericApplicationContext context = new GenericWebApplicationContext();
prepareContext(context);
customizeBeanFactory(context.getDefaultListableBeanFactory());
createBeanDefinitionReader(context).loadBeanDefinitions(locations);
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
customizeContext(context);
context.refresh();
context.registerShutdownHook();
return context;
}

Now you are ready to test web controller classes. In spring framewor Http request and response mock are off the shelf.

Tuesday, November 25, 2008

biding jobs ?

when we look at the Poland there are some very important biding systems. Allegro ... ... ... ... well ok there is only one. We have eBay but as they have not very successful start it is like saing we have świstak.
But to my surprise you can bid for work. not literally ;) but look at that. freaky ;)

The minor changes

There must be such a day once a year (at least once). Something has passed away something comes. I am back to Poznan. I want to follow the path of technical blogging. Eclipse, Springframework, Ruby (from scratch) are topic of higher attention this month. And as I am going to blog about eclipse on our enthusiasts' blog the other topics will be commented here.
Hopefully I will find some time and energy to do that.

Tuesday, August 26, 2008

Does anyone need an Eclipse developer?


GSOC is about to end.
There is a time for change. Maybe not at the moment but in very near future. I have some reasons, personal one to move to Frankfurt for a longer time. The personal one.
If you are looking for Eclipse developer, Java (plain, Struts2, Spring, Hibernate ...), requirements engineer, analyst, designer. If you are looking for such a person in nearby Frankfurt/Main, Mainz, or for remote work. Please let me know.
If you are doing software architecture analysis or think about doing that, or you are looking for young software architect who want to learn, and learns real fast you are my dreamed employer ;)

End of the GSOC 2008



It was nice adventure with the GSOC this year. But my journey with the PDE customization support is not finished. We need to make it as useful as we can.
But I owe all of you some summary. What we have on board:

  • Remove features from tree (Views, Commands etc.. - in general all IPluginElements / IPluginExtensions if you are familiar with the PDE Product model)
  • Changing name of nodes.
  • Launching product with transformations
  • Exporting product with transformations


To make it work make sure that transformation hook is located in the same place as org.eclipse.osgi. It can be issue during the launch (when you exporting all plug-ins ends in the same location).

Code is in the same place it was before - so in code.google.com repo. If you want to make it run you will probably need also ant.ui from the Eclipse HEAD, as I also try to sync the pde.core and pde.ui with the HEAD (cause next step is to make Product Customizations part of Eclipse 3.5 Mx).

If you want to watch presentation please use this link (I've resigned from youtube hosting cause I cannot place there high quality movies) or the uncompressed version with annotations.

Thursday, July 24, 2008

Product configuration will let you set plugin options


So what was the path to this point. First I implemented some Product Customization features. Then I was struggling with product export function but finally it works. Just recently I've started to work on launching with transformations. And now is time for changes. We should be able to add users possibility to set plug-ins properties. Start level, osgi properties ...
What I can say it is not small step for me and big for the mankind, it's rather opposite.
Any way as programming in Eclipse is making life simpler, I hope this new feature will make it simpler for some of you. At the screen shoot how it look at the moment.

Tuesday, July 22, 2008

Product Customization - reactivation

It is time to start with the second part. As you can easy see if you tried use the Product Customization tooling, as it is now, there is much to do. As removal parts of description works pretty well there is no other type of action supported at the moment.
Another feature missing is launching product with the transformations applied. This problem affects more than just Product Customization tooling and it is now described in this bug. If you have any comments feel free to share with us.
I'm starting working... this is first task on my GSOC list for the second part of the program.

Monday, July 14, 2008

Reckoning

We can distinguish variety of aspect in our lives. They are semi-dependent, overlapping, fluent.
It's great when you can find path through your life and are able to cope with them all. Steering your life through the ocean of decisions.
I was wondering how it looks in my case. Well let me focus on so called "professionals life" cause my private I wish keep private.
So, scientific carrier: teaching students, software engineering, software architecture knowledge but rather from books and meetings with professionals than form my own experience. Bioinformatics: C++, perl, math, probability theory, evolution substitution models, dynamic programming algorithms, MCMC etc. World dimly known.
Professional activity: consulting - web applications (struts2 rather than EJB), Eclipse as developer, embedded software C++ (long time ago),
There is a bit more, but the point is that I've started wondering how many ways must you go to get somewhere.
However sometimes possibilities you have are your limitation. Signed contract, agreements, previous choices. Decide and be decisive. But what to do when you decide live your life ? What if you want be happy here and now ?
Yup and once again the area I want to keep for myself. And it just look like this, what matters in my life is it's private part. These moments you get up for every day.