2 Replies Latest reply on Jul 20, 2016 3:33 PM by Nik G

    jboss-cli-client.jar and jython

    Alessandro Fioretti Newbie

      Dear All,

       

      Can you help me? I'm trying to use jboss-cli-client.jar with jython as described on Advanced CLI scripting with Groovy, Rhino, Jython, etc. but I receive this error message:

       

      java.lang.IllegalStateException: java.lang.IllegalStateException: Unable to initialize command context.

       

      I'm using JBoss EAP 6.2.

       

      I run jython in this way

       

      java -jar jython.2.5.3.jar -Djava.class.path="./jboss-cli-client.jar:."

       

      and then I append "jboss-cli-client.jar" to sys.path

       

      >>> import sys

       

      >>> sys.path.append("./jboss-cli-client.jar")

       

      >>> from java.util import Date

       

      >>> from org.jboss.as.cli.scriptsupport import CLI

       

      >>> cli = CLI.newInstance() 

       

      >>> cli.connect("myhostname.localdomain", 9999, "myuser", "mypwd")

       

      Traceback (most recent call last):

       

        File "<stdin>", line 1, in <module>

       

              at org.jboss.as.cli.scriptsupport.CLI.connect(CLI.java:117)

       

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

       

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

       

              at java.lang.reflect.Method.invoke(Method.java:606)

       

      java.lang.IllegalStateException: java.lang.IllegalStateException: Unable to initialize command context.

       

      Any idea on where can I investigate to solve?

       

      Thanks in advance.

       

       

      Ale

        • 1. Re: jboss-cli-client.jar and jython
          Alessandro Fioretti Newbie

          Solved!

           

          The problem was how I was loading jython.

          Using java -jar jython.2.5.3.jar -Djava.class.path="./jboss-cli-client.jar:." the jboss-cli-client.jar is not loaded into CLASSPATH so the Java ClassLoader does not find all classes needed for execution.

           

          To properly load Java jars into jython we must run it as follows:

           

          java -cp "/home/jboss/jython.2.5.3.jar:/home/jboss/jboss-cli-client.jar:.:${CLASSPATH}" org.python.util.jython

           

          In this way I'm able to connect to JBoss:

           

          Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35)

          [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_45

          Type "help", "copyright", "credits" or "license" for more information.

          >>> from java.util import Date

          >>> from org.jboss.as.cli.scriptsupport import CLI

          >>> cli = CLI.newInstance()

          >>> cli.connect("localhost.localdomain", 9999, "user", "pwd")

          WARN: can't find jboss-cli.xml. Using default configuration values.

          >>>

           

          I hope it's help.

           

          Alessandro.

          • 2. Re: jboss-cli-client.jar and jython
            Nik G Newbie

            I was facing the same issue.. cool.. works now.

            Thanks Alessandro.