gpt4 book ai didi

logging - Wildfly java.lang.NoClassDefFoundError : org/jboss/modules/ModuleLoader when using custom logging formatter

转载 作者:行者123 更新时间:2023-12-04 18:57:20 26 4
gpt4 key购买 nike

我在 Wildfly 10 中使用默认的 jboss-logging (LogManager),并尝试创建自己的日志格式化程序。

我在standalone.xml中这样配置它:

    <subsystem xmlns="urn:jboss:domain:logging:3.0">
<use-deployment-logging-config value="false"/>
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="JSON_PATTERN"/>
</formatter>
</console-handler>
<formatter name="JSON_PATTERN">
<custom-formatter
class="com.mycompany.JsonLogFormatter"
module="com.mycompany.logging"/>
</formatter>
</subsystem>

我创建了一个这样的 jboss 模块:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mycompany.logging">
<resources>
<resource-root path="log-utils-1.0.0.jar" />
</resources>
<dependencies>
<module name="javax.json.api"/>
<module name="org.jboss.logmanager" />
<module name="org.jboss.logging" />
<module name="org.jboss.modules"/>
</dependencies>
</module>

其中 log-utils-1.0.0.jar 包含我的 JsonLogFormatter 类,并且与 module.xml 位于同一目录中(位于 $JBOSS_HOME/modules/com/mycompany/logging/main)

启动 wildfly 容器时,它无法启动,我看到了这个异常:
java.lang.IllegalArgumentException: Failed to load module "com.mycompany.logging" for formatter "JSON_PATTERN"
at org.jboss.logmanager.config.AbstractPropertyConfiguration.<init>(AbstractPropertyConfiguration.java:64) [jboss-logmanager-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.logmanager.config.FormatterConfigurationImpl.<init>(FormatterConfigurationImpl.java:30) [jboss-logmanager-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.logmanager.config.LogContextConfigurationImpl.addFormatterConfiguration(LogContextConfigurationImpl.java:171) [jboss-logmanager-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.as.logging.logmanager.ConfigurationPersistence.addFormatterConfiguration(ConfigurationPersistence.java:218)
at org.jboss.as.logging.CustomFormatterResourceDefinition$2.performRuntime(CustomFormatterResourceDefinition.java:117)
at org.jboss.as.logging.LoggingOperations$LoggingAddOperationStepHandler$1.execute(LoggingOperations.java:204)
at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1329) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:493) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:387) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:349) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:397) [wildfly-server-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:366) [wildfly-server-2.2.0.Final.jar:2.2.0.Final]
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299) [wildfly-controller-2.2.0.Final.jar:2.2.0.Final]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_151]
Caused by: java.lang.NoClassDefFoundError: org/jboss/modules/ModuleLoader
at org.jboss.logmanager.config.AbstractPropertyConfiguration$ModuleFinder.getClassLoader(AbstractPropertyConfiguration.java:463) [jboss-logmanager-2.0.4.Final.jar:2.0.4.Final]
at org.jboss.logmanager.config.AbstractPropertyConfiguration.<init>(AbstractPropertyConfiguration.java:62) [jboss-logmanager-2.0.4.Final.jar:2.0.4.Final]
... 16 more

最佳答案

当我将以下参数添加到 JAVA_OPTS 环境时,我能够获得一个干净的启动,没有异常:

JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/jboss-modules.jar"

我从这个页面得到了这个想法: https://inspectit-performance.atlassian.net/wiki/spaces/DOC17/pages/54657166/JBoss+6.x

更新信息:

我的全套 JAVA_OPTS 如下:
-server -Xms2048m -Xmx2048m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m 
-Djava.net.preferIPv4Stack=true
-Djava.awt.headless=true
-Djboss.https.port=8443
-Djboss.http.port=8080
-Djboss.bind.address=0.0.0.0
-Djboss.server.log.dir=/home/app/logs
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n
-DconfigurationLocationStrategy=filesystem
-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager
-Xbootclasspath/p:/home/app/wildfly/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.0.4.Final.jar
-Xbootclasspath/p:/home/app/wildfly/jboss-modules.jar
-javaagent:/opt/prometheus/jmx_prometheus_java_agent.jar=31500:/opt/prometheus/prometheus.yaml

似乎需要执行所有 logmanager 属性是因为我已经在容器中部署了 prometheus 代理。

如果我不部署 prometheus 代理,我不需要将任何 logmanager 参数添加到 JAVA_OPTS。不幸的是,不部署此代理不是一种选择。

关于logging - Wildfly java.lang.NoClassDefFoundError : org/jboss/modules/ModuleLoader when using custom logging formatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49330032/

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