Recent Posts
Archives

PostHeaderIcon (long tweet) How to make ChromeOS work in VirtualBox without Wifi?

Case

How to make ChromeOS work in VirtualBox without Wifi, ie on an ethernet/wired local network, or even offline?

Quick Fix

Shutdown the VM > Select it > Settings > Network > Advanced > Adapter Type > select “Paravirtualized Network (virtio-net)”

PostHeaderIcon (long tweet) Virtual Box / PAE processor

Case

On booting ChromeOS Vanilla within Virtual Box, I got the following error:
[java]This kernel requires the following features not present on the CPU: pae
Unable to boot – please use a kernel appropriate for your CPU.[/java]

(Actually, the problem occured with ChromeOS but may have appened with another system)

Quick Fix

In Virtual Box, select the VM > Settings > Processor > check “Enable PAE/NX”.

PostHeaderIcon (long tweet) A story of return in try/catch/finally

A short reminder: in a try/catch/finally section, the block in the finally is always executed. “Always” means “even if a return statement is reached in the try or catch“.

A short piece of code shows more than a long speech. The following JUnit test ends with no error:
[java]package com.stepinfo.poc.cartography;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;

/**
* Created with IntelliJ IDEA 12 "Leda" CE
* User: Jonathan LALOU
* Date: 08/Apr/13
* Time: 22:41
*/
public class TestTryCatchFinally {

public static final String TRY = "try";
public static final String CATCH = "catch";
public static final String FINALLY = "finally";

private String tryVersusFinally() {
try {
return TRY;
} catch (Exception e) {
return CATCH;
} finally {
return FINALLY;
}
}

private String catchVersusFinally() {
try {
throw new RuntimeException();
} catch (Exception e) {
return CATCH;
} finally {
return FINALLY;
}
}

@Test
public void testTryFinally() {
assertNotSame(TRY, tryVersusFinally());
assertEquals(FINALLY, tryVersusFinally());
}

@Test
public void testCatchFinally() {
assertNotSame(CATCH, tryVersusFinally());
assertEquals(FINALLY, catchVersusFinally());
}
}
[/java]

PostHeaderIcon (long tweet) java.lang.SecurityException: Prohibited package name

Case

Here is a case of stupid error. I started up a new project in IntelliJ IDEA, laying on a Maven archetype. On launching the first unit test, I got the following error:
[java]Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.lalou.jonathan.multiposts[/java]

Quick fix

As you may have noticed, the package name was prefixed with java.… which is prohibited by the JDK. An immediate fix is to restore a package name not starting with java..

The code in the JDK is explicit: the exception with such a message is raised in a unique occasion:
[java] if ((name != null) && name.startsWith("java.")) {
throw new SecurityException
("Prohibited package name: " +
name.substring(0, name.lastIndexOf(‘.’)));
}
[/java]

PostHeaderIcon Retour sur Devoxx FR 2013

J’ai eu la chance d’assister a la derniere journee de DevoxxFR a Paris, le vendredi 29/03/2013, pour le compte de mon employeur StepInfo, sponsor de l’evenement. Voici quelques impressions en vrac

General

  • C’est bien organise, il y a du monde, et excepte au moment du depart au niveau des vestiaires, il n’y a pas eu de gros souci de logistique.
  • Les entreprises sponsors ont joue le jeu 😉
  • Que ce soit au niveau des stands ou des conferences, la domination des Mac est ecrasante! Google a reussi a mettre en valeur ses ChromeBooks, mais j’ai vu peu de Windows et encore moins de Linux.
  • J’ai pu assister a 4 conferences, toutes interessantes, mais d’un niveau heterogene, je reviens dessus plus en detail ci-dessous.

IDE Java : astuces de productivité pour le quotidien

La conference est animee par Xavier Hanin (@xavierhanin). Il y presente les trois IDE phares du monde Java: NetBeans, Eclipse et IntelliJ IDEA.

Maitrisant plutot bien IDEA, je n’ai pas appris de choses fondamentales sur mon IDE, si ce n’est le raccourci Ctrl+Shift+A pour afficher les intentions. J’ai connu NetBeans a ses debuts (Forte puis Sun ONE), mais j’en ai totalement perdu la maitrise depuis des annees. Quant a Eclipse, il m’arrive de le lancer quelques fois par an pour des problematiques clients specifiques, mais je suis contraint d’avoir recours a la souris en quasi-permanence ; sous IDEA c’est tres rare.

Un “sondage” assez grossier des personnes dans la salle a donne des resultats interessants: ~15% des developpeurs presents utilisent NetBeans, ~25% IDEA et ~90/95% Eclipse.

Quick Start avec le Cloud Google

La conference est animee par Didier Girard de SFEIR et Alexis Moussine-Pouchkine de Google France. Les principaux outils de Google pour le cloud sont presentes, en prenant pour hypothese de creer une startup: une solution “a l’ancienne”, avec serveurs d’applications, gestion materielle etc. est avancee, avant de ceder la place a une solution entierement sur le cloud de Google.

En un mot: c’est tres convaincant.
Je regrette que le sujet n’ait pas ete elargi vers des solutions cloud alternatives, comme celle d’Amazon.

The Spring Update: Looking at Spring 3.1, 3.2, and 4.0

La presentation est menee par Josh Long de SpringSource. On se rend compte tres rapidement que ne serait-ce que pour la qualite du show, nous les Francais (voire les Latins) nous sommes largement en dessous de la qualite des Anglo-Saxons.

Josh enonce ses concepts, donne des exemples, met l’eau a la bouche. Au bout de 50′ de conference, je n’ai plus qu’une envie: retourner coder avec les dernieres versions de Spring!

Parmi toutes les nouveautes, j’en retiens deux:

  • l’AnnotationConfigApplicationContext, qui m’evitera de taper d’ecrire un bloc comme:[xml]    <context:component-scan annotation-config="true" base-package="lalou.jonathan.beans"/>[/xml]
  • l’integration future des websockets d’HTML5 pour obeir a la norme JEE7 d’ici la fin de l’annee.

Ce dernier point m’interesse particulierement, en raison d’un projet sur lequel je travaille actuellement, et dont nombre de problemes seraient resolus par les websockets de JEE7. Theoriquement, et potentiellement, d’ici la fin de l’annee 2013, nous pourrions integrer une brique “Spring JEE7” avec websocket au sein d’un WebSphere 8 (donc non JEE7-compliant), au lieu d’etre dependant dans la prochaine release du serveur d’applications d’IBM.

Josh:

Entre HPC et big data: un case study sur la simulation du risque de contrepartie

C’est la conference dont j’ai vu le moins le rapport avec Devoxx, mais ayant passe 7 ans dans la finance de marche j’y ai trouve mon interet. En passant, j’y ai vu le seul PC sous Windows de toutes les conferences :-D.

Le theme de cette conference est: comment deporter une partie du calcul intensif de Monte-Carlo du CPU vers les GPU? Ces derniers ont une taille et une structure de memoire radicalement differente de celles des CPU (CPU+RAM pour etre plus precis). Les GPU permettent d’effectuer des masses de calcul en un temps bien plus faible (jusqu’a 99% de gain) qu’en architecture classique, moyennant une reecriture du code C en un autre langage adapte, par exemple OpenCL.

Les deux speakers, de Murex, sont Adrien Tay Pamart (visiblement pas tres a l’aise en mode geek) et Jonathan Lellouche pour la partie technique.

Durant les questions, l’existence de ponts Java vers OpenCL, comme JavaCL est evoquee. Il est dommage de ne pas avoir plus de temps pour creuser ce theme.

5 ans et 500 releases en 50 minutes !

La presentation est dirigee par Freddy Mallet  et Olivier Gaudin de Sonar.

La demonstration est rudement bien faite. Les dirigeant de SonarSource retracent, dans un ordre plus ou moins chronologique, les problemes, ou les impediments a-t-on envie de dire, rencontres en 5 ans sur Sonar.
Quelques themes forts: le context switching est une plaie, on ne gere pas une entreprise commerciale avec des clients comme un simple projet open source, etc.

En guise de conclusion

Devoxx a repondu aux attentes que j’avais en y entrant:

  • une journee de formation intensive et motivante
  • revoir des “anciennes tetes”
  • echanger des cartes de visite

Qu’il me soit donc permis ici de remercier StepInfo pour m’avoir permis d’acceder a cette journee, ainsi que les organisateurs de Devoxx pour le travail qu’il ont accompli.

Vivement DevoxxFR 2014!

PostHeaderIcon Maven: How to use jars in a lib/ folder?

Case

I have to work on an “old-school” project: without Maven (and even without integration within Eclipse). The JARs depended on by the application are located in a lib/ folder. Besides, I cannot add JARs to company repository.
How to integrate Maven with this lib/ folder?

Solution

First of all, you have to enable the support of Maven within IntelliJ IDEA: select the project > right click > add framework support > select Maven.

Create a pom.xml and complete the main information.
Identify the JARs which are relatively common (eg those available in http://repo1.maven.org/maven2/), and add them as dependencies.

Now, you still have to deal with “uncommon” JARs

Quick and (very) dirty

The quickest way is to add the JARs as dependencies, declared with scope system, eg:
[xml]<dependency>
<groupId>unknownGroupId</groupId>
<artifactId>someArtifactId</artifactId>
<version>someVersion</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/foo.jar</systemPath>
</dependency>[/xml]

The main drawback of this dirty solution is that when you generate your archive, the JARs depended on with scope system will not be exported… Quiet a limitation, isn’t it?

(A bit) Slower and (far) cleaner

You have to declare a “remote repository”, of which URL is local, such as:
[xml]<repository>
<id>pseudoRemoteRepo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<url>file://${project.basedir}/lib</url>
</repository>[/xml]

Then, declare the dependencies like:
[xml]<dependency>
<groupId>UNKNOWN</groupId>
<artifactId>foo</artifactId>
<version>UNKNOWN</version>
</dependency>[/xml]
Move and/or rename the JARs, for instance from lib/foo.jar folder to the actual one, such as lib/UNKNOWN/foo/foo-UNKNOWN.jar.

Now it should be OK ;-).
In my case I prefered to add Maven Assembly plugin with the goal jar-with-dependencies, to be sure to build a unique JAR with complete exploded dependencies.

PostHeaderIcon Tutorial: a Windows XP as guest VM in Virtual Box

Target and Constraints

I need a Windows XP running as a virtual machine (VM).  Don’t think of using your former OEM licence, it won’t work: Windows checks and makes a difference between OEM and other licences.

Microsoft provides VHD files: you can consider them as “virtual” HDD. Officially, these VHD files are intented at developpers to test their websites on various Windows (XP to Seven) and Internet versions (6 to 9).

The VHD files provided for Windows XP need a licence key to be activated, and therefore have two main drawbacks:

  1. after three days and/or three reboots, the system will allow you to log in anymore. That’s quiet a limitation :-(.
  2. But wait, there’s even worse: the VHD file provided by Microsoft will be completely disabled on February 14th, 2013!

At last, I stress on having an absolutely legal solution, since it will be deployed both on personnal (Ubuntu) and professional (Windows 8 ) desktop computers. I do not want to waste my time playing hide and seek with authorities.

Prerequisites

In this post I will assume you are a bit familiar with working on VirtualBox. If you are not, then browse the web, ask Google, RTFM, or, at last, leave a message in the comments, I’ll try to figure out a moment to write a short tutorial.

Operations

Classic

  • Create a VM within VirtualBox
  • Name it “Windows XP” for instance
  • Set the VHD file as the one downloaded and unzipped above.

Specific

  • Run the VM. You must log in as IEUser. The default password is Password1 (on French keyboards: Pqsszord&)
  • Do not validate the licence.
  • The VM will require CmBatt.sys(and possibly another one):
    • On host system: mount SP3 iso device > CD/DVD Devices> Choose a virtual CD/DVD virtual file > select WinXP SP3 ISO (xpsp3_5512.080413-2113_usa_x86fre_spcd.iso)
    • On guest system: run the CD, eg: Windows+E > D:\ > Autoplay > Install. All the files will be unzipped in a folder such as C:\1a2b3c4d5e... (with hexadecimal value).
    • In the frame asking for CmBatt.sys, select it in C:\1a2b3c4d5e...\i386
  • Windows XP will ask for drivers and try to download them. But the ethernet card has not yet been installed!
    • On host system:
      • Mount the  ethernet_drivers_for_WinXP_VirtualBox.iso (cf. above for details)
      • Devices > Install Guest Additions > accept all
    • On guest system: manually install drivers for ethernet card.
  • In order to bypass the limitation of February 14th,
    • if you read this post after February 14th, 2013: set the system time to January 1st 2013 for instance (I didn’t test ; it should work)
    • disable time synchronization between host and guest systems, eg:[java]$VIRTUALBOX_HOME/app32/VBoxManage setextradata "Windows XP" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1[/java]

Now everything should work. I suggest to take a snapshot ;-), and then to revert to it as often as needed.

Conclusions

Officialy, the VHD files provided by Microsoft are intented at developpers who need test their websites on obsolete and out-of-date browsers like Internet Explorer. But you can imagine many other usages. On my side, the interest is to have VM as a module in a complete integrated testing environment and in the frame of a software forge.

My opinion? The solution provided by Microsoft does exist, it’s better than nothing ; anyway, implementing it is a far hard matter. Limitations and complexity of install spoil the user experience. It’s a pity, because the idea of VHD is great, but does not match that of precompiled open source Virtual Boxes: http://www.virtualboxes.org

PostHeaderIcon Sosh vs Free Mobile

Depuis quelques jours j’ai quitte Free Mobile. En resume, le reseau n’est toujours pas au niveau, malgre de recentes ameliorations. Le gros point noir reste la data en 3G, ce qui pour moi est le besoin fondamental pour lequel j’investis dans un smartphone et un abonnement telephonique, alors qu’une simple carte prepayee suffirait largement a mes 30 ou 45 minutes de communication telephonique mensuelles.

Je suis donc passe chez Sosh. Premier bilan apres quelques semaines:

  • Sosh, ca fonctionne mieux que Free Mobile. Je modere toutefois ce jugement, car si le reseau, les debits et le ping sont sensiblement meilleurs, il n’y a rien de fulgurant. Meme sur le reseau de Orange, il m’arrive souvent de perdre l’UMTS et de retomber en EDGE, voire meme de perdre la connexion data.
  • J’ai de nouveau acces Google Maps (et Navigation), ainsi que Google Play, et mes flux RSS sont mis a jour plus regulierement. Ces derniers temps, il me fallait 10 a 15 minutes avant de pouvoir me servir du GPS!
  • Je peux lancer un streaming avec une probabilite raisonnable que ca fonctionne
  • La batterie de mon Nexus recupere une duree de vie normale ; chez Free, a cause notamment du basculement regulier d’antenne, il m’etait necessaire de charger deux voire trois fois durant la journee!
  • Si le reseau fonctionne bien, la logistique n’est par contre pas au point:
    • commande passee un jeudi, carte SIM recue le mercredi suivant.
    • portage de numero demande pour le samedi d’apres la livraison, mais sera effectue le jeudi d’apres, ie deux semaines apres avoir passe la commande!
    • l’interface de gestion de compte utilisateur n’est pas vraiment bien faite (avis personnel).

Bref, meme si ca coute plus cher, au moins ca marche! Je ne suis pas encore alle a New-York ou Mumbai pour verifier le fonctionnement a l’etranger, mais je ne pense pas qu’il y ait de probleme particulier.

Je ne jetterai pas la pierre a Free Mobile ni a Xavier Niel: je leur suis reconnaissant d’avoir fait chuter les prix des abonnements mobiles en quelques mois. Je retournerai peut-etre chez Free dans quelques mois, si leur reseau devient digne de ce nom. Pour le moment, je refuse de payer 15.99€ pour un service qui fonctionne “de temps en temps”… et jamais quand c’est urgent :-@

PostHeaderIcon (long tweet) How to get the average of a Date column in MySQL?

Case

You have a column of type Date in MySQL. How to get the average value of this series?

(Don’t think to execute select AVG(myColumnDate), it won’t work!)

Fix

Use a query similar to this:

[sql]SELECT FROM_UNIXTIME( ROUND( AVG( UNIX_TIMESTAMP( myDateColumn ) ) ) )

FROM `myTable`

WHERE 1[/sql]

PostHeaderIcon Tomcat: How to deploy in root?

Case

You have a WAR to deploy on Tomcat, let’s say jonathan.war for instance. Usually, the application will be reached through the URL http://machine:port/jonathan.
Let’s say you would like to exclude the WAR name from the address, ie the application to be reached on http://machine:port/. This operation is called “to deploy in root”, since the context will be simple slash: '/'.

Solution

You can implement that with two means:

  • rename the war as ROOT.war, then deploy.
  • or: edit conf/server.xml, replace [xml]<context>[/xml] with
    [xml]<context path="" docBase="jonathan" debug="0" reloadable="true"> [/xml]