Improve the performance of your Maven builds with maven-cli-plugin

When you makes a lot of build using Maven, this is quickly a pain to wait for the end of the build. So this is always good to have solutions to improve the performances of the builds.

The better improvement i found until now is the maven-cli-plugin. This plugin provides an interactive command line interface to launch builds. The improvement is that the first phases of the build are made only once. So multiple builds are really faster. We loose a little time at the first build to make some caching improvements.

With these features, I save a lot of time when I made a lot of builds. For example a simple clean takes sometimes 20 seconds on a big multimodule project. When using the cli, it takes 20 seconds including the time to load the shell for the first time and then it takes only 1 second the make the following cleans. The effect is the same on other phases like install, package, compile, ...

The installation is quite simple. First you must add a plugin group to the settings.xml file :


And then add a new repository for the manve-cli-plugin :

          <name> Maven 2 Repository</name>

And you just have to use the following command on a Maven project :

mvn cli:execute-phase

With that the plugin will be downloaded automatically and the next commands will be executed directly.

The usage is very easy. This plugin has 2 useful goals :

  • execute : Open a shell and allows you to execute goals of plugins.
  • execute-phase : Open a shell and allows you to execute phases of the maven build.

The main difference is that if you launch install from the execute-phase, all the preceding phases will be executed, but that's not the case with execute, only install will be executed.

Personally, I only execute phases, so I always use the execute-phase of the cli plugin.

When you're in the shell, you can launch several phases or goals :

maven> clean install

And you can directly add arguments in the command :

maven> clean install -Dmaven.test.skip=true

And when you are building a multimodule projects, you can also execute phases only on several modules :

maven> module1 module2 module3 clean install

You can use the ls command in a multi module project to list all the modules of the project. You can use the "Tab" key to auto complete the goals, phases and modules name.

When you've finished your builds, you can simply use the "exit" command to exit from the command line.

I think it's really a great essential plugin for each person who make Maven builds.

More information on the official site.

Evernote : A very smart note-book

Like any developer, I write a lot of notes with different tools :

  • A lot of paper
  • Office Word
  • My iPhone
  • My emails
  • Web applications like RememberTheMilk

I use them depending on what I do and  where I am. But this not a really good way to manage notes. The notes are not centralized and I've not always them when I need them.

Some days ago, I discovered a new web application than can perhaps solve my problem. This web tool is Evernote.

The site allows you to store elements on the web or offline in your storage space and organize all the elements like you want. With Evernote, you can :

  • Write TODO List
  • Write some notes
  • Send them by email
  • Take screenshot
  • Add photo
  • Capture contents of web pages
  • Record audio records

But there is more, this service make also Optical Character Recognition (OCR) in your images. So when you take a picture and send them in the Evernote account, the text in the photo is indexed and taken for your next searches. All the text of the other documents is of course also indexed. So with that you can search documents easily.

Evernote is also more than an web application, it's also a desktop client for Windows and Mac OS. There is also Windows Mobile, Java and soon iPhone versions. With the client versions, you can directly drag and drop content to your account.

So to resume, Evernote is a kind of aggregator for your content. So after writing something on paper, you can take a picture and add it to your Evernote and then make searches in your content. With the free registration, you have 40MB of upload monthly. To have more upload capacity, you can pay the premium account for 5$/month.

For more informations, you can consult the Official site

Java Concurrency : Part 2 - Manipulate Threads

After seeing how to create Threads, we'll see in this article what we can do to manipulate Threads.

When we've Threads, we can make several operations on the Threads :

  • Make the current Thread sleeping during x milliseconds
  • Wait for an other thread to complete
  • Manage the priorities of Threads and pause a thread to give an other thread the opportunity to run
  • Interrupt a thread

We'll now see how to do all these things.

Read more…

Tip : Add resources dynamically to a ClassLoader

Theoretically, it's not possible to ad resources to a ClassLoader in Java after creation. I say theoretically, because, we can do that using Reflection.

In fact, the URLClassLoader class has a addUrl(URL url) method to add a new URL, so we can invoke that method to add an URL where the ClassLoader can search to load a class. But this method is protected. So here is an example taking advantage of Reflection to add URL to the system ClassLoader :

public static void addURLToSystemClassLoader(URL url) throws IntrospectionException { 
  URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); 
  Class<urlclassloader> classLoaderClass = URLClassLoader.class; 

  try { 
    Method method = classLoaderClass.getDeclaredMethod("addURL", new Class[]{URL.class}); 
    method.invoke(systemClassLoader, new Object[]{url}); 
  } catch (Throwable t) { 
    throw new IntrospectionException("Error when adding url to system ClassLoader "); 

This is easy and that can be done for any URLClassLoader. But of course, this is an ugly hack and that must not be always used but can be useful sometimes. An other way to do that is to create a new Class extending URLClassLoader and make the addUrl(URL url) public, but that can be done with the system ClassLoader.

Java Concurrency - Part 1 : Threads

This post is the first of set of posts about Java Concurrency.

The concurrency is the fact to made several things at the same time using several threads.

A thread, also called Lightweight Process, is treatment unity. Threads executes code in parallel of each other threads currently running. When you've only one processor, there is a thread running at the same time of the others, you only have the impression of concurrency (I don't say it's not useful, I say it's different), but when you've multiple processors, you'll see the power of multithreading. In this case, you can have your threads distributed on the processors of the computer.

Read more…

Develop a modular application – Bases

This is the first post of four posts about modular applications.

I'll try to explain all the things we must think of when we develop a modular application. I'm developing a generic core for modular applications, JTheque. So what I'm saying in this posts are taken from my experience developing this framework.

In this post, i'll start talking of the bases of the conception of modular application. So what's a modular application, a module and what give to the developer and the user to have a modular application ? In the next posts, I'll describe the problems we could found relating to modules and loading. The examples will be in Java, but all the concepts can be applied to every language. I'll not talk about OSGi, this is more an introduction to modular programming without specific framework, but of course, OSGi is a very good solution to modular programming.

Of course, I don't think i'm a professional in modular programming and what I'll say in this post, is nothing else than my point of view. If you think there is better solutions than what I present, don't hesitate to say that in comments.

Read more…

Sonar 2.1 has been released

The version 2.1 of Sonar has just been released. This version includes 51 bugfixes and improvements. The major new features are :

  • A new page "Librairies" displays all the librairies of the project (Maven dependencies)
  • A new page "Dependencies" searches for library usages
  • A new page "System Info" display the system properties, installed plugins, database and VM memory stats.
  • New rules to detect unused methods.

Normally, all the plugins compatible with version 2.0 should be compatible with this new version.