Maven2からmainメソッドを実行(exec-maven-pluginでS2アプリ)

exec-maven-pluginを使えばMaven2からmainメソッドを実行出来ます。

Test.java

package jp.co.abby.test;
public class Test {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello World!");
    }
}

pom.xml

・・・略・・・
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.0.2</version>
    <configuration>
      <executable>java</executable>
      <mainClass>jp.co.abby.test.Test</mainClass>
    </configuration>
  </plugin>
・・・略・・・

こんな設定で、mvn exec:java で実行可能

[INFO] [exec:java]
Hello World!

こんなの誰だって出来ちゃう。

どうしても出来なかったのがドキュメントにも書いてあるclasspathの設定。

        <configuration>
          <executable>java</executable>
          <arguments>
            <argument>-Dmyproperty=myvalue</argument>
            <argument>-classpath</argument>
            <!-- automatically creates the classpath using all project dependencies, 
                 also adding the project build directory -->
            <classpath/>
            <argument>com.example.Main</argument>
            ...
          </arguments>
        </configuration>
        <configuration>
          <executable>java</executable>
          <arguments>
            <argument>-Dmyproperty=myvalue</argument>
            <argument>-classpath</argument>
            <classpath>
              <dependency>commons-io:commons-io</dependency>
              <dependency>commons-lang:commons-lang</dependency>
            </classpath>
            <argument>com.example.Main</argument>
            ...
          </arguments>
        </configuration>

これは動かない。エラー出ます。

[INFO] Trace
java.lang.ArrayStoreException
        at java.lang.System.arraycopy(Native Method)
        at java.util.ArrayList.toArray(ArrayList.java:305)
        at org.codehaus.plexus.component.configurator.converters.composite.ArrayConverter.fromConfiguration(ArrayConverter.java:141)

同じような事を外国のMLとかで出てたけど解決には至ってない。
明示的にclasspathを指定する方法はどうすれば良いのか未だ不明...

Test.javaを少し変更してS2(2.3)絡めた場合

package jp.co.abby.test;
public class Test {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello World!");
        SingletonS2ContainerFactory.init();
    }
}

dependencyが正しく記述されていれば実行可能です。


argumentのclasspathは謎のまま><