作为日志记录工具,我使用 Log4j2,这是通过使用系统属性(/VM 参数)调用的,使用:
-Dlog4j.configurationFile=./config/log4j2_config.xml
为了编译我的项目,我使用 Maven 并创建 exe 文件 Launch4j(插件: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 集成的系统属性?!
如果尝试将其放在括号中并带有“opt”( http://launch4j.sourceforge.net/docs.html )
或者类似的东西:
<vars>
<var>-Dlog4j.configurationFile=./config/log4j2_config.xml</var>
</vars>
但是两者都不起作用,并且我的记录器没有记录..
也许您也遇到了同样的问题并且可以帮助我。
感谢您的帮助!
最佳答案
我不熟悉launch4j或maven插件,但是according to the Ant docs ,您可以使用 <opt>
指定系统属性标签。而且maven插件文档说pom结构是相似的,所以你尝试使用<opt>
<jre>
内的标签 标签?
喜欢
<jre>
<opt>-Dlog4j.configurationFile=./config/log4j2_config.xml</opt>
</jre>
尝试一下,让我知道它是否有效。
现在有一个问题:
您为配置使用不同的名称是否有原因?通常文件名是log4j2.xml
。如果您使用该名称,则应自动加载配置,并且您不需要系统属性。
关于java - 在 Maven 中为 Launch4j 添加系统属性(使用 Log4j 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28673323/