我有一个项目,它使用一个自定义的log4j2 appender,当通过带有maven jar-with-dependencies程序集的java命令行正常启动时,它可以正常工作。
但是,当我使用launch4j创建一个exe包装器时,无法找到appender。错误:
2016-10-05 07:24:25,796 main ERROR Appenders contains an invalid element or attribute "InMemRotAppender"
2016-10-05 07:24:25,812 main ERROR Unable to locate appender "InMemRotAppender" for logger config "root"
可能是什么问题?
log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" packages="priv.mtj.jjpv">
<Appenders>
<InMemRotAppender name="InMemRotAppender">
</InMemRotAppender>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="InMemRotAppender" />
</Root>
</Loggers>
</Configuration>
Appender(位于同一个项目中并打包到同一个jar中):
package priv.mtj.jjpv;
....
@Plugin(name = "InMemRotAppender", category = "Core", elementType = "appender", printObject = true)
public class InMemRotAppender extends AbstractAppender {
...
}
Launch4j config:
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>console</headerType> <!-- normally gui -->
<jar>C:\workspace\jjpv\target\jjpv-0.0.1-SNAPSHOT-jar-with-dependencies.jar</jar>
<outfile>C:\workspace\jjpv\deploy\jjpv.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>C:\workspace\jjpv\deploy\jpview.ico</icon>
<classPath>
<mainClass>priv.mtj.jjpv.JJPv</mainClass>
</classPath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJdk</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</launch4jConfig>