2011-09-27 2 views
6

私はexec-maven-pluginで実行しているプロジェクトでlog4jを使用しようとしています。私は次の場所にファイルを配置しようとしています。ファイルのすべての場所についてはMaven Exec Pluginを使用する場合、log4j.propertiesをどこに置くべきですか?

$PROJECT_HOME 
$PROJECT_HOME/src/main/resources 
$PROJECT_HOME/target 
$PROJECT_HOME/target/classes 

を、私はコードを実行し、次のメッセージを取得しています:log4j.propertiesファイルが置かれるべき

log4j:WARN No appenders could be found for logger (mypacakge.MyClass). 
log4j:WARN Please initialize the log4j system properly. 


のexec-のmaven-pluginの設定:

... 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2</version> 
    <configuration> 
     <mainClass>mypackage.Main</mainClass> 
    </configuration> 
</plugin> 
... 
+0

あなたの 'exec-maven-plugin'設定を追加できますか? – amra

+0

execプラグインはどの実行フェーズにバインドされていますか? – MaDa

答えて

0

私はこれが正しい方法(私はこのプラグインを知らないので)であるわからないんだけど、あなたはの構成を使用することができますプラグインを使用して、VMのクラスパスにファイルの正しい場所を指定します。

<configuration> 
    <executable>maven</executable> 
    <!-- optional --> 
    <workingDirectory>/tmp</workingDirectory> 
    <arguments> 
     <argument>-classpath</argument> 
     <argument>/path/to/dirthatcontainslog4J</argument> 
     ... 
    </arguments> 
</configuration> 

このようなプラグインを使用する目的は何ですか? このアプリケーションをテストするためにある、あなたはおそらく、Mavenの依存性・プラグインを使用する必要がある場合:http://www.sonatype.com/books/mvnex-book/reference/customizing-sect-custom-packaged.html

あなたがここでより多くの情報を見つけることができます。 maven jar-with-dependencies log4j

How can I create an executable JAR with dependencies using Maven?

よろしく

1

あなたを次の2つの選択肢があります。

  1. プロパティファイルを

./src/main/resources/log4j.xml

  1. あなたは、コマンドラインから指定することができます

$ MVN execをコンパイルします。java -Dexec.classpathScope =コンパイル-Dexec.mainClass = com.lei.java.sample.Test -Dlog4j.configuration = file:./log4j.xml

0

実際、log4jは、構成ファイルを手動で見つけるためのコマンドラインオプションのサポートを提供しています。しかし、それはjavaコマンドそのもののために使用されている、あなたは直接Javaオプションを渡す-Dexec.argsオプションを使用してMavenの建物の中にそれを使用することができます。

$ mvn -Dexec.args="-Dlog4j.configurationFile='./log4j2.xml' -classpath /previously/configured/path" org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 

はまた、exec.args内の引数もas said in document、モジョの<arguments>セクションに永続的に書き込むことができます。

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.6.0</version> 
    <executions> 
    ... 
    </executions> 
    <configuration> 
    <executable>maven</executable> 
    <arguments> 
     <argument>-Dlog4j.configurationFile="./log4j2.xml"</argument> 
     ... 
    </arguments> 
    </configuration> 
</plugin>