2015-02-23 28 views
0

正如我使用Log4j2測井工具,這是通過使用系統屬性(/ VM參數),使用調用:添加對Launch4j系統屬性Maven中(使用的Log4j 2)

-Dlog4j.configurationFile=./config/log4j2_config.xml 

對於編譯我使用Maven創建的項目以及創建exe文件Launch4j(Plugin:com.akathist.maven.plugins.launch4j)。

在我的pom.xml的插件定義看起來像這樣:現在

<plugin> 
    <groupId>com.akathist.maven.plugins.launch4j</groupId> 
    <artifactId>launch4j-maven-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
     <execution> 
      <id>l4j-clui</id> 
      <phase>package</phase> 
      <goals> 
       <goal>launch4j</goal> 
      </goals> 
      <configuration> 
       <headerType>gui</headerType> 
       <cmdLine>./config/MyConfig.xml</cmdLine> 
       <opt>com.akathist.maven.plugins.launch4j.configurationFile=./config/log4j2_config.xml</opt> 
       <jar>${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar</jar> 
       <outfile>${project.build.directory}/MyExe.exe</outfile> 
       <downloadUrl>http://java.com/download</downloadUrl> 
       <classPath> 
        <mainClass>de.my.path.MainClass</mainClass> 
        <!-- <preCp>anything</preCp> --> 
       </classPath> 
       <!-- <icon>${project.basedir}/src/main/assembly/application.ico</icon> --> 
       <jre> 
        <minVersion>1.7.0_00</minVersion> 
        <!-- <jdkPreference>preferJre</jdkPreference> --> 
       </jre> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

我的問題是:

我如何可以設置log4j2集成的系統屬性?

如果試圖把它放在括號與「選擇」(http://launch4j.sourceforge.net/docs.html

或類似的東西:

     <vars> 
          <var>-Dlog4j.configurationFile=./config/log4j2_config.xml</var> 
         </vars> 

但兩者沒有工作,我的記錄器不記錄..

也許你有同樣的問題,可以幫助我。

謝謝你的幫助!

回答

2

我不熟悉launch4j或maven插件,但according to the Ant docs,您使用<opt>標籤指定系統屬性。而maven插件文檔說,pom結構是相似的,所以你嘗試使用<opt>標籤裏面的<jre>標籤?

<jre> 
     <opt>-Dlog4j.configurationFile=./config/log4j2_config.xml</opt> 
    </jre> 

試一下,讓我知道,如果它的工作原理。

現在一個問題:

是否有您使用的是不同的名稱爲您配置一個原因是什麼?通常文件名是log4j2.xml。如果你使用這個名字,配置應該自動加載,你不需要系統屬性。

+1

嘿!第一個機會沒有工作..文件重命名log4j2.xml,並把它放在src文件夾(http://stackoverflow.com/questions/25487116/log4j2-configuration-no-log4j2-configuration-file-found)的工作! !現在,我寫了這個插件的作者,因爲在我看來,添加系統屬性的機會應該是可能的,並且是一個更好的解決方案。 – mrbela 2015-02-24 11:18:34

-1
<opts> 
    <opt>-Dlog4j.configuration=file:log4j.xml</opt> 
</opts>