JBoss Command Line Utility Twiddle

Recently I had faced a situation where I was forced to invoke a method on a particular “MBean” 10-15 times. I had completed this task manually from “JMX-Console”, but I didn’t feel it was elegant way of executing the task.

So I had started doing research to find out if there is better way of doing this task. Finally I found a utility called as “twiddle” which basically comes with every JBoss installation. In this article, I am just sharing information about what I had learned. There are many more complex tasks which can be performed with this utility.


JBOSS_HOME :- This is the location where JBoss is installed.

Prerequisites :-

We need to set “JAVA_HOME” variable before executing twiddle. This can be done in two ways.
Solution 1:-

In the Profile :- In “bash profile”(I use ‘bash’ profile, same can be done with other profiles), so go to “HOME” directory( enter “cd” at command prompt), open “.bash_profile(make sure there is “dot” before “bash_profile”, this is secret file) and enter below lines.

JAVA_HOME=<location where “java” is installed>
export JAVA_HOME

Save the file and enter “source .bash_profile”. “source” command reads commands from the file and executes in current shell environment.

Solution 2 :-

Update “twiddle.sh”(Take backup before editing the file).
Add below lines

JAVA_HOME=<location where “java” is installed>
export JAVA_HOME

Note :- Solution “2” is better than “1” because solution 1 might effect other applications too, but solution “2” will effect only “twiddle.sh”

Validation :-

Enter “echo ${JAVA_HOME}” , this should return the location where the JBoss is installed. If this variable returns “empty” value, then this variable is not set properly, please check above steps.


Go to the directory “JBOSS_HOME/bin” and execute “./twiddle.sh”. It should display the help options.

Help :-

./twiddle.sh –help-commands :- displays all the commands we can invoke on this utility.
./twiddle.sh –H<command> :- will provide additional information on particular command, such as syntax of the commands, options that can be passed to the command.

Example :-
./twiddle.sh -Hinvoke

Syntax :-

./twiddle.sh -s <serverUrl> -u <userName> -p <password> <command> [ command_arguments

serverUrl :- <protocol>://<serverName>:<port>
protocol :- jnp ( This is optional)
serverName :- Since we will be executing the command from the box where JBoss is installed, we can either give “localhost” or actual server name.
port :- 1099.  This the port where Jboss Naming service is listening. If you are using out of box Jboss installation then this will be the port. But if you changed this and you don’t remember the port, then either check the file “JBOSS_HOME/server/<serverName>/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml” or log on to “http://<serverName>:<port>/jmx-console” and click on “jboss” on left column and then click “service=Naming” and the value for the attribute “port”.

Commands :-

jsr77 :- displays jsr77 related information.
xmbean :- print out mbean metadata as an “xmbean” descriptor. In this file you can find all attributes and operations on a particular mbean.
info :- get the metdata for an MBean.
get :-  get value for an mbean attribute.
invoke :- invoke an operation on an MBean
create :- create an MBean
setattrs :- set the values of one or more MBean attributes
unregister :- unregister one or more MBeans
queryMethod :- query list of matchin methods on MBeans
listDomains :-  list all the domains.
query :-  query list of matching MBeans
set :- set the value for one MBean attribute
serverinfo :- get the information about MBean Server.

Examples :-

jsr77 :-

Displays the “jsr77” information for this particular server.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin jsr77

xmbean :-

Displays information of the MBean as “xmbean” descriptor.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming

info :-

Query attribute of a particular bean.

./twiddle.sh -s jnp://localhost:1099 -u admin -p admin xmbean jboss:service=Naming

get :-

Get value of a particular ‘attribute’.

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss:service=Naming’ Name

Get value of a multiple ‘attributes’. The attributes must be separated by ‘Space’.

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss:service=Naming’ Name State

invoke :-

Invoke operation on a particular mbean.

./twiddle.sh -s localhost:1099 -u admin -p admin invoke jboss.system:type=ServerInfo listThreadCpuUtilization

Note :- There are multiple additional options, I didn’t explore them as of now.

create :-

Create an MBean.

I didn’t explore this command, I need to do research on this command a little more. I will update this article once I found more on this command.

setattrs :-

Set values of one or more bean attributes.

In below command we set values of two attributes “BackLog” and “JNPServerSocketFactoryBean” to “100” and “null” respectively.

./twiddle.sh -s localhost:1099 -u admin -p admin setattrs ‘jboss:service=Naming’ Backlog 100 JNPServerSocketFactory null

unregister :-

Unregister a one or more Mbeans.

Again I didn’t get much chance to explore this command, will update on this on this command once I am done with research.

queryMethod :-

Query all methods on all Mbeans.

./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod list

Query methods on few mbeans

./twiddle.sh -s localhost:1099 -u admin -p admin queryMethod -f ‘jboss:*’ list

listDomains :-

List all the domains.

./twiddle.sh -s localhost:1099 -u admin -p admin listDomains

query :-

Display all Mbeans on the server.

./twiddle.sh -s localhost:1099 -u admin -p admin query ‘*:*’

Display MBeans on particular domain. In below command we display in the domain “jboss:j2ee”.

./twiddle.sh -s localhost:1099 -u admin -p admin query ‘jboss.j2ee:*’

set :-

Set the value on particular attribute.

./twiddle.sh -s localhost:1099 -u admin -p admin set ‘jboss.system:service=Logging,type=Log4jService’ RefreshPeriod 60

serverinfo :-

Display information about MBean server.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -l

Number of MBeans on the server.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -c

Default Domain.

./twiddle.sh -s localhost:1099 -u admin -p admin serverinfo -d

Few Important Useful Operations :- We can do many operations with “Twiddle”, below are just few examples.

Deploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ deploy “file:///tmp/VASVijay/VASApp.war”

Undeploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ undeploy “file:///tmp/VASVijay/VASApp.war”

Redeploying an Application :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.service:MainDeployer’ redeploy “file:///tmp/VASVijay/VASApp.war”

Take ThreadDump :-

./twiddle.sh -s localhost:1099 -u admin -p admin invoke ‘jboss.system:type=ServerInfo’ listThreadDump
Get Server Info :-

./twiddle.sh -s localhost:1099 -u admin -p admin get ‘jboss.system:type=ServerInfo’

Issues :-

Twiddle will be throwing exception like below, this is a know nexception. This is because “twiddle” is executed on separate “JVM” from the “JBoss JVM”. There is patch for this at “https://issues.jboss.org/browse/JBAS-4323”

10:16:57,158 ERROR [Twiddle] Exec failed java.io.NotSerializableException: org.jboss.resource.connectionmanager.TxConnectionManager
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.ArrayList.writeObject(ArrayList.java:570)
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 java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)

Pending Tasks :-

Exploring below commands and options :-

Options :- “-c” option. I was not able to find out correct way to execute this option, so I am checking out with Redhat on this option. If any one of you know how to use this option, please let me know. Thanks in advance for sharing the solution.

Commands :- “create” and “unregister” commands,  I need to write code to explore these. I will soon add examples to execute these commands, once I test these commands successfully.

References :-

This article wouldn’t had been possible without ‘google’ and many wonderful articles written by experts. Few of them are below. I referenced many sites for this utility, I couldn’t remember all site names, If I didn’t mention any particular site name whose example I had used,  its just that I don’t remember the site name, I sincerely apologize for not mentioning the site name.  Please let know if any one feels I had missed to add any particular site in the reference, I will add the site to the references.



I hope that you all liked this article, if there any issues or suggestions or if you don’t like anything in the article,  please comment.

For some more Twiddle examples, refer the below post.




Dream, Learn, Share and Inspire !