Wildfly java.lang.NoClassDefFoundError: org/jboss/modules/ModuleLoader when using custom logging formatter
Wildfly java.lang.NoClassDefFoundError: org/jboss/modules/ModuleLoader when using custom logging formatter
我在 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 class 并且位于与 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.performRuntime(CustomFormatterResourceDefinition.java:117)
at org.jboss.as.logging.LoggingOperations$LoggingAddOperationStepHandler.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.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 环境时,我能够干净地启动,w/o 异常:
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。不幸的是,不部署此代理不是一种选择。
我在 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 class 并且位于与 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.performRuntime(CustomFormatterResourceDefinition.java:117)
at org.jboss.as.logging.LoggingOperations$LoggingAddOperationStepHandler.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.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 环境时,我能够干净地启动,w/o 异常:
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。不幸的是,不部署此代理不是一种选择。