2015-02-23 31 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>