使用自定义日志记录格式化程序时,Wildfly java.lang.NoClassDefFoundError:org / jboss / modules / ModuleLoader

时间:2018-03-16 21:53:43

标签: logging jboss noclassdeffounderror wildfly-10

我在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

1 个答案:

答案 0 :(得分:4)

当我将以下参数添加到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。遗憾的是,不能部署此代理不是一种选择。