Uploaded image for project: 'WildFly Core'
  1. WildFly Core
  2. WFCORE-1580

the "cli" Maven module: should the JBoss LogManager dependency be optional?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.0.Alpha18
    • 2.1.0.Final
    • CLI
    • None

      Say I have a very simple Java program using the WildFly CLI scripting facilities:

          public static void main(String[] args) throws Exception {
              CLI cli = CLI.newInstance();
              cli.connect();
              System.out.println(cli.cmd(":whoami").getResponse());
              cli.disconnect();
          }
      

      This is in a small Maven project that has a single dependency:

              <dependency>
                  <groupId>org.wildfly.core</groupId>
                  <artifactId>wildfly-cli</artifactId>
                  <version>2.1.0.Final</version>
              </dependency>
      

      When trying to run the program (no matter if there's a running WildFly server or not), I get the following exception:

      Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logmanager/LogContextSelector
      	at org.jboss.as.cli.embedded.EmbeddedControllerHandlerRegistrar.registerEmbeddedCommands(EmbeddedControllerHandlerRegistrar.java:89)
      	at org.jboss.as.cli.impl.CommandContextImpl.initCommands(CommandContextImpl.java:581)
      	at org.jboss.as.cli.impl.CommandContextImpl.<init>(CommandContextImpl.java:302)
      	at org.jboss.as.cli.impl.CommandContextFactoryImpl.newCommandContext(CommandContextFactoryImpl.java:44)
      	at org.jboss.as.cli.scriptsupport.CLI.connect(CLI.java:80)
      	at cz.ladicek.foobar.Main.main(Main.java:8)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
      Caused by: java.lang.ClassNotFoundException: org.jboss.logmanager.LogContextSelector
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      	... 11 more
      

      This is because CommandContextImpl's constructor calls EmbedServerHandler.create and for the EmbedServerHandler class to load, there has to be JBoss LogManager present on the classpath.

      The wildfly-cli Maven module already has a dependency on JBoss LogManager, except that...

              <dependency>
                  <groupId>org.jboss.logmanager</groupId>
                  <artifactId>jboss-logmanager</artifactId>
                  <optional>true</optional>
              </dependency>
      

      It's optional. I guess this made sense in WildFly Core 1.x which didn't have server embedding, but in WildFly Core 2.x, I wonder if the dependency should be mandatory.

      Thoughts?

            jdenise@redhat.com Jean Francois Denise
            lthon@redhat.com Ladislav Thon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: