How to register a SPI implementation when running exec:java
<p>I'm trying to make <a href="http://vertx.io/docs/vertx-dropwizard-metrics/java/" rel="nofollow">VertX Mertrics</a> work when running via the <code>exec:java</code> Maven plugin.</p>

<p>All works as expected when I package the application into a fatjar and run it with <code>java -jar fat.jar -conf config.json -Dvertx.metrics.options.enabled=true</code></p>

<p>When I run it with <code>mvn clean package exec:java -DskipTests</code> I see:
<code>
2016-03-22 18:39:58.833 WARN  i.v.c.i.VertxImpl:348 - Metrics has been set to enabled but no VertxMetricsFactory found on classpath
</code></p>

<p>I tried several approaches:</p>

<ul>
<li>adding <code>io.vertx:vertx-dropwizard-metrics:3.2.1</code> as compile dependency</li>
<li>create an in-house metrics implementation and register it by means of <code>src/main/resources/META-INF/services/io.vertx.core.spi.VertxMetricsFactory</code> file (double-checked that it's actually copied to <code>target/classes/META-INF/services/io.vertx.core.spi.VertxMetricsFactory</code>)</li>
<li>also adding <code>${basedir}/src/main/resources</code> as additional classpath element (in addition to previous point)</li>
</ul>

<p>I have double-checked in the debugger that <code>ServiceLoader</code> actually returns an empty iterator.</p>

<p>This is my exec-plugin config:
<code>
                &lt;plugin&gt;
                    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                    &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                    &lt;configuration&gt;
                        &lt;additionalClasspathElements&gt;
                            &lt;element&gt;${basedir}/src/main/resources&lt;/element&gt;
                        &lt;/additionalClasspathElements&gt;
                        &lt;mainClass&gt;io.vertx.core.Launcher&lt;/mainClass&gt;
                        &lt;commandlineArgs&gt;run ${vertx.mainVerticle} -conf ${vertx.config}&lt;/commandlineArgs&gt;
                        &lt;systemProperties&gt;
                            &lt;systemProperty&gt;
                                &lt;key&gt;vertx.logger-delegate-factory-class-name&lt;/key&gt;
                                &lt;value&gt;io.vertx.core.logging.SLF4JLogDelegateFactory&lt;/value&gt;
                            &lt;/systemProperty&gt;
                            &lt;systemProperty&gt;
                                &lt;key&gt;vertx.metrics.options.enabled&lt;/key&gt;
                                &lt;value&gt;true&lt;/value&gt;
                            &lt;/systemProperty&gt;
                        &lt;/systemProperties&gt;
                    &lt;/configuration&gt;
                &lt;/plugin&gt;
</code></p>

<p>Here is <code>exec:exec</code> configuration that <strong>does work</strong>, but I want to understand if and why it's (im-)possible to do it with <code>exec:java</code></p>

<p><code>
        &lt;profile&gt;
            &lt;id&gt;exec&lt;/id&gt;
            &lt;build&gt;
                &lt;plugins&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                        &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                        &lt;executions&gt;
                            &lt;execution&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;exec&lt;/goal&gt;
                                &lt;/goals&gt;
                                &lt;phase&gt;process-classes&lt;/phase&gt;
                                &lt;configuration&gt;
                                    &lt;executable&gt;java&lt;/executable&gt;
                                    &lt;arguments&gt;
                                        &lt;argument&gt;-Dvertx.metrics.options.enabled=true&lt;/argument&gt;
                                        &lt;argument&gt;-Dvertx.logger-delegate-factory-class-name=${vertx.logger-delegate-factory-class-name}&lt;/argument&gt;
                                        &lt;argument&gt;-classpath&lt;/argument&gt;
                                        &lt;classpath /&gt;
                                        &lt;argument&gt;io.vertx.core.Launcher&lt;/argument&gt;
                                        &lt;argument&gt;run&lt;/argument&gt;
                                        &lt;argument&gt;${vertx.mainVerticle}&lt;/argument&gt;
                                        &lt;argument&gt;-conf&lt;/argument&gt;
                                        &lt;argument&gt;${vertx.config}&lt;/argument&gt;
                                    &lt;/arguments&gt;
                                &lt;/configuration&gt;
                            &lt;/execution&gt;
                        &lt;/executions&gt;
                    &lt;/plugin&gt;
                &lt;/plugins&gt;
            &lt;/build&gt;
        &lt;/profile&gt;
</code></p>