5

I created a java application and initialize a java.util.Logger with that application and run that application as -javaagent with jboss AS 7 server and i got IllegalStateException (i am using eclipse IDE).Here follows my logger initialization code


static public void setup() throws IOException {

        // Get the global logger to configure it
        Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

        logger.setLevel(Level.INFO);
        fileTxt = new FileHandler("C:/Users/abc/Desktop/ATAGENT/Logging.txt");
        fileHTML = new FileHandler("C:/Users/abc/Desktop/ATAGENT/Logging.html");

        // create txt Formatter
        formatterTxt = new SimpleFormatter();
        fileTxt.setFormatter(formatterTxt);
        logger.addHandler(fileTxt);

        // create HTML Formatter
        formatterHTML = new BMITHtmlFormatter();
        fileHTML.setFormatter(formatterHTML);
        logger.addHandler(fileHTML);
      }

When i create -javaagent jar appended with above lines of code and run with jboss as7 server i got following exception


WARNING: Failed to load the specified log manager class org.jboss.logmanager.LogManager
Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.jboss.as.server.Main.main(Main.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.modules.Module.run(Module.java:260)
    at org.jboss.modules.Main.main(Main.java:291)
Caused by: java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
    at org.jboss.logmanager.Logger.getLogger(Logger.java:60)
    at org.jboss.logmanager.log4j.BridgeRepositorySelector.(BridgeRepositorySelector.java:42)
    ... 7 more

And i serched in fourms and i got a solution which is Open the launch configuration for the server definition. and add -logmodule org.jboss.logmanager to the program arguments before org.jboss.as.standalone. But it results the same exception with some additional warning. Here follows the exception


WARNING: -logmodule is deprecated. Please use the system property 'java.util.logging.manager' or the 'java.util.logging.LogManager' service loader.
WARNING: Failed to load the specified log manager class org.jboss.logmanager.LogManager
Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.jboss.as.server.Main.main(Main.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.modules.Module.run(Module.java:260)
    at org.jboss.modules.Main.main(Main.java:291)
Caused by: java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
    at org.jboss.logmanager.Logger.getLogger(Logger.java:60)
    at org.jboss.logmanager.log4j.BridgeRepositorySelector.(BridgeRepositorySelector.java:42)
    ... 7 more

4

3 回答 3

21

我在使用 JBOSS EAP 6 时遇到了同样的问题,我花了 2 天时间才找到解决方案!

原因是您的代理需要在启动时创建一个 Logger,他需要能够在 JBOSS 模块初始化之前访问 logmanager 类。您需要将 JBoss LogManager 添加到引导类加载器。然后,通过 ModuleClassLoader 可用的 LogManager 和通过系统类加载器加载的类之间会发生冲突。

解决方案是让 Java 代理和 JBoss 模块使用相同的类加载器来加载 LogManager 类。

对于 EAP 6,在您的standalone.conf(或域)中(对于您的版本必须关闭)

添加

JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/modules/org/jboss/logmanager/main/jboss-logmanager-1.3.1.jar"

为了使 Java 代理和 JBoss 模块使用相同的类加载器

在添加 org.jboss.logmanager 时修改这段代码,如下所示:

if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then
    JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager"
fi

希望这会有所帮助。

于 2014-03-04T10:02:51.530 回答
9

我在下面的链接中搜索了几天后找到了解决方案。 https://github.com/jbossas/jboss-as-maven-plugin/issues/40#issuecomment-14943429

我必须稍作调整才能在Windows 7中工作。

  1. 打开 Eclipse。
  2. 添加 Jboss 7.1 Runtime 1 服务器。
  3. 选择服务器并按 F3。
  4. 单击打开启动配置。
  5. 转到 VM 参数。
  6. 添加以下两个条目。

“-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager” “-Djava.util.logging.manager=org.jboss.logmanager.LogManager”

现在选择类路径选项卡

  1. 选择用户条目
  2. 单击添加外部罐子
  3. 选择三个jar文件

a) jboss-logmanager-1.2.0.GA.jar b) jboss-logmanager-log4j-1.0.0.GA.jar c) log4j-1.2.16.jar

路径

  1. C:/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/main/jboss-logmanager-1.2.0.GA.jar"
  2. C:/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/log4j/main/jboss-logmanager-log4j-1.0.0.GA.jar"
  3. C:/jboss-as-7.1.1.Final/modules/org/apache/log4j/main/log4j-1.2.16.jar"

这将毫无问题地启动独立的 jboss。

于 2014-06-21T14:58:53.427 回答
0

在 EAP 6.4 中,正确的 logmanager 路径应该是 $JBOSS_HOME/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-1.5.4.Final-redhat-1.jar

于 2015-10-26T22:03:22.867 回答