Maven项目中的log4j2配置问题

时间:2014-07-25 19:23:42

标签: java maven log4j

我将我的log4j2.xml文件放到目录:src/main/resources中,然后我创建jar-with-dependencies并编译它显示

dk994@dk994-Lenovo-IdeaPad-Z510:~/Pulpit/Pracbaza/exercise1$ java -cp target/exercise1-1.0-SNAPSHOT-jar-with-dependencies.jar com.spica.project.App
[Fatal Error] :1:10: The processing instruction target matching "[xX][mM][lL]" is not allowed.
ERROR StatusLogger Error parsing jar:file:/home/dk994/Pulpit/Pracbaza/exercise1/target/exercise1-1.0-SNAPSHOT-jar-with-dependencies.jar!/log4j2.xml org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 10; The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:134)
    at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:44)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:455)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:429)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:415)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
    at com.spica.project.App.<clinit>(App.java:10)

ERROR StatusLogger No logging configuration
21:19:15.331 [main] ERROR com.spica.project.App - error
Hello World!

我将此文件从apache站点

复制到我的log4j.xml文件中
 <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="WARN">
    <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
    <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    </Appenders>
    <Loggers>
    <Root level="error">
    <AppenderRef ref="Console"/>
    </Root>
    </Loggers>
    </Configuration>

我该怎么办? 我在Ubuntu上工作,这是一个简单的maven项目,通过终端

创建

1 个答案:

答案 0 :(得分:5)

中删除前导空格字符
 <?xml version="1.0" encoding="UTF-8"?>

在XML声明之前有任何字符是错误的。

相关问题