gpt4 book ai didi

java - Maven 项目中的 log4j2 配置问题

转载 作者:行者123 更新时间:2023-11-29 07:46:54 24 4
gpt4 key购买 nike

我将我的 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 项目,通过终端创建

最佳答案

从中删除前导空白字符

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

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

关于java - Maven 项目中的 log4j2 配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24963101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com