[TIP] TomEE/OpenEJB Arquillian and Maven resolver

New ShrinkWrap Maven resolver is awesome to avoid to handle all dependencies manually but it can be a bit long to resolve dependencies. We just introduced a hack in TomEE and OpenEJB adapters to make it less painful. The idea is quite simple: do the resolution while the container is starting up.

To use it simply use the property “preloadClasses” in arquillian.xml listing some classes to preload. You’ll typically initialize in a static block your dependencies in a Future.

Here is a sample arquillian.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <container qualifier="openejb" default="true">
      <property name="preloadClasses">org.superbiz.Dependencies</property>

And here is the Dependencies class:

package org.superbiz;

import org.jboss.shrinkwrap.resolver.api.maven.Maven;

import java.io.File;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Dependencies {
    private static final Future<File[]> DEPENDENCIES;
    static {
        final ExecutorService es = Executors.newSingleThreadExecutor();
        DEPENDENCIES = es.submit(new Callable<File[]>() {
            public File[] call() throws Exception {
                return Maven.resolver()

    public static File[] get() {
        System.out.println(new Date());
        try {
            return DEPENDENCIES.get(); // block if not done or return immediately
        } catch (final Exception e) {
            throw new RuntimeException(e);
        } finally {
            System.out.println(new Date());

Of course you can use this idea for anything taking time in your client tests!

Have a nice hacking 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s