简体   繁体   English

Maven项目中的log4j2配置问题

[英]log4j2 configuration issue in Maven project

I put my log4j2.xml file to directory: src/main/resources and after I make jar-with-dependencies and I compile this it shows 我将我的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!

I literaly copied this to my log4j.xml file from apache site 我从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>

What should I do? 我该怎么办? I work on Ubuntu and this is simple maven project, created via terminal 我在Ubuntu上工作,这是通过终端创建的简单的Maven项目

Delete the leading whitespace character from 从中删除前导空白字符

 <?xml version="1.0" encoding="UTF-8"?>

It's an error to have any characters before the XML declaration. 在XML声明之前包含任何字符是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM