2012-03-23 4 views
3

でjarファイルを起動します。私のPOMのは、私は現在のプロジェクトのポストの実行フェーズの間、M2のレポ内の別のJarファイルを起動するプロジェクトを、持っているM2リポジトリ

サンプルスケルトン

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.1</version> 

      <executions> 
       <execution> 
       <id>exec-one</id> 
       <phase>verify</phase> 
       <configuration> 
        executable>java</executable> 
        <arguments> <argument>-jar</argument> 
        <argument>JarToInvoke.jar</argument> 
        </arguments>     
        <**workingDirectory**>/C:/path to repo</workingDirectory> 
        </configuration> 
         <goals> 
         <goal>exec</goal> 
         </goals> 
        </execution> 
        </executions> 

       <dependencies> <dependency> 
       <groupId>GroupId of JarToInvoke</groupId> 
       <artifactId>JarToInvoke</artifactId> 
       <version>1.0.0-SNAPSHOT</version> 
       </dependency> 
       </dependencies> 
      </plugin>  
      </plugins> 

私はMavenの-EXEC-プラグインを使用してみましたが、次の問題を持ちます。

  1. ここで、JarToInvoke依存関係を指定する必要がありますか?プロジェクト依存関係またはexec-plugin依存関係ハードコーディング作業ディレクトリ(/ C:/レポへのパス)で

  2. 、私はJarToInvokeアーティファクトを呼び出すことができています。しかし、それは良い解決策ではありません。最終的に、このプロジェクトは、異なるOSを持つどんなm/cでも実行する必要があるからです。では、プロジェクトのM2リポジトリ(既定のクラスパス)でJarToInvoke成果物を検索するためにexec-pluginを作成するにはどうすればよいですか?

作業ディレクトリのM2 repoパスをハードコーディングするうちに、JarToInvokeアーティファクトを呼び出すことができました。しかし、JarToInvoke成果物を実行している間に別の依存関係の問題が発生すると、JarToInvokeへのlog4j依存関係のいくつかが見つかりませんでした。 JarToInvokeを陰影のついた瓶にして、期待どおりに動作します。しかし、永続的なまたは良い解決策ではありません(影付きのjarサイズは35 MBです)。 exec-pluginにM2リポジトリ内の依存Jarファイルを探すように指示するにはどうすればよいですか?

ご意見をお寄せください。前もって感謝します。

答えて

0

Execプラグインのドキュメントのexample pageは、私が思うものを説明しています。

exec:execの代わりにexec:javaの目標を使用できる場合は、JVMを見つけることが必要です。また、プラグインの設定オプションをincludeProjectDependenciesincludePluginDependenciesに変更することで、プラグインの依存関係やプロジェクトの依存関係を引き出すこともできます。

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.1</version> 

    <executions> 
     <execution> 
      <id>exec-one</id> 
      <phase>verify</phase> 
      <configuration> 
       <includeProjectDependencies>false</includeProjectDependencies> 
       <includePluginDependencies>true</includePluginDependencies> 
       <executableDependency> 
        <groupId>GroupId of JarToInvoke</groupId> 
        <artifactId>JarToInvoke</artifactId> 
       </executableDependency> 

       <!-- Look up the main class from the manifest inside your dependency's JAR --> 
       <mainClass>com.example.Main</mainClass> 
       <arguments> 
        <!-- Add any arguments after your JAR here ---> 
       </arguments> 
      </configuration> 
      <goals> 
       <goal>java</goal> 
      </goals> 
     </execution> 
    </executions> 

    <dependencies> 
     <dependency> 
      <groupId>GroupId of JarToInvoke</groupId> 
      <artifactId>JarToInvoke</artifactId> 
      <version>1.0.0-SNAPSHOT</version> 
     </dependency> 
    </dependencies> 
</plugin>  

唯一の欠点は、実行するJARのメインクラスを明示的に指定する必要があることです。依存関係のJARでマニフェストを開き、Main-Class属性を読み取ることでこれを調べることができます。

あなた本当にあなたは(そのよう${project.build.directory}/execの-瓶など)事前に定義された場所にローカルリポジトリから依存関係をコピーすると、あなたは、このディレクトリを養うことができますMavenの依存関係のプラグインのcopy-dependencies目標を使用することができ、exec:execを使用する必要がある場合execプラグインのworkingDirectory設定オプションにあります。

+0

貴重な情報をお寄せいただきありがとうございます。しかし、上記のようにPOMを設定した後、次の例外がスローされます。 – appu

+0

'java.lang.reflect.InvocationTargetException \t at sun.reflect.NativeMethodAccessorImpl.invoke0(ネイティブメソッド) \t at sun.reflect.NativeMethodAccessorImpl。呼び出し(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invokeで \t(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invokeで \t(Method.java:597)org.codehausで \t .msojo.exec.ExecJavaMojo $ 1.run(ExecJavaMojo.java:297)\t at java.lang.Thread.run(Thread.java:662) ' – appu

+0

@ RahulR.Prasadこれはasmライブラリとは異なるバージョンのJarを実行するときにJarToInvokeが引き込まれると予想されます。 'com.tvworks.testing.tools'クラスが必要とするasmのバージョンのexecプラグインに依存関係を明示的に追加してみてください。 – prunge

0

おそらく、jarファイルの絶対パスを見つける簡単な方法は、maven-dependency-pluginpropertiesゴールとすることです。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.3</version> 
    <executions> 
     <execution> 
     <goals> 
      <goal>properties</goal> 
     </goals> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.1</version> 

     <executions> 
      <execution> 
      <id>exec-one</id> 
      <phase>verify</phase> 
      <configuration> 
       <executable>java</executable> 
       <arguments> 
        <argument>-jar</argument> 
        <argument>${GroupIdofJarToInvoke:JarToInvoke:jar}</argument> 
       </arguments>     
       <workingDirectory>/C:/path to repo</workingDirectory> 
       </configuration> 
        <goals> 
         <goal>exec</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin>  
     </plugins> 

     <dependencies> 
      <dependency> 
       <groupId>GroupIdofJarToInvoke</groupId> 
       <artifactId>JarToInvoke</artifactId> 
       <version>1.0.0-SNAPSHOT</version> 
      </dependency> 
     <dependencies> 
関連する問題