In a development environment, we write many applications that depend on third party libraries. So when the development of the application goes on, we depend on different versions of the third party libraries. The big Question is how are we going to organize these third party libraries in JBoss?
JBoss provides us with different options in organizing the libraries.
Client: the client directory contains libraries that are to be used by an application if it needs to communicate with the server instance. For example, if we write an application which connects to a JBoss server instance, then all the jars in this client directory should be available in application class path. We generally don’t place our libraries in directory unless we are writing a JBoss client application or when we are extending JBoss server functionality. If we need to use libraries in this, we can use jbossall-client.jar available in this directory in place all jars.
Lib: the lib directory contains jars that should be available to all servers in order to run. This directory contains server startup libraries. We place our libraries when we are extending the server functionality.dont place your library unless needed.
Common/lib: This directory contains libraries that are to be shared across all server profiles. If we need to provide any global library that is to be used by all applications in all server profiles, we can place the library here.
Lib/endorsed: This directory contains libraries that JBoss uses. If we need to override with a new version of library that JBoss uses, we can place them here.
JBoss/server/server instance/lib: This is the place where we place our instance specific libraries.
Twiddle is a command line tool provided by JBoss to communicate with the JMX server instance. Twiddle tool can be used to get information about the beans, server and also to get and set values to the attributes. We can also use twiddle to invoke various operations.
The tool is available in JBOSS_HOME/bin directory. We can either use twiddle.sh or twiddle.bat.Twiddle provides an extensive help system. Open a command prompt and move to JBOSS_HOME/bin and enter
twiddle.bat –h, which displays the basic help system.
The twiddle command allows one to write own scripts to perform management tasks. The tasks performed by the twiddle command are transient and if the server is restarted the changes are not seen.
The following are the twiddle commands available
jsr77 Print out JSR77 related information
xmbean Print out mbean metadata as an xmbean descriptor
info Get the metadata for an MBean
get Get the values of one or more MBean attributes
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 the server for a list of matching methods of MBeans
listDomains Query the server for a list of available domains
query Query the server for a list of matching MBeans
set Set the value of one MBean attribute
serverinfo Get information about the MBean server
So in this article we will see some of the important commands and put them to work.
Serverinfo: To get basic information about the server, we can use the “serverinfo” command like
This will return the list of the names that belong to the Jca mbean and then
?twiddle.bat -s localhost query jboss.system:*
jboss.system:service=MainDeployer
jboss.system:service=ServiceBindingManager
jboss.system:type=Log4jService,service=Logging
jboss.system:service=ThreadPool
jboss.system:type=Server
jboss.system:service=ServiceController
jboss.system:type=ServerConfig
jboss.system:type=ServerInfo
We made a query to the server for the mbean jboss.system.This query is very useful when we need to find information about the server which will be useful in
getting thread dumps
to get time spent on threads
type of underlying architecture
Server configurations e.t.c.
The 2 mbean Server, ServerConfig and Serverinfo provides various levels of information about the server
Server: provides information about the version of Jboss server in use.
ServerConfig: provides various information about the server configuration in use.
ServerInfo: provdes various information about the underlying architecture.
To query all the web application available in the server we can use
NOTE: when we deploy the application using the MainDeployer mbean, the application is available temporarily. The application will be deployed temporarily and can be accessible until the server gets shutdown.
Note: the twiddle supports only archive files to be deployed .we cannot use twiddle to deploy exploded directories.
For the above snippet, we can see that the username and password are provided in a plain text format. JBoss allows us to use security domains which help us in providing encrypted passwords in the place of plain text password. In this article we will see how we can encrypt a password and provide it in the place of plain text password and still use the Datasource. For this we will use security domain in login-config.xml.
Security Domain: security domains are an abstraction used to secure all the requests that are made to a component. These are bound to JNDI and configured at a server level. These security domains can be used by any component. These are bound under “Java:/jaas”.
So now we will generate an encrypted password for the password that we want to use for the Datasource, in order to do this execute the command passing the text [password to be used as an argument]
We got the encrypted password. So now we will configure a security domain with the username and password defined in it. We will use the default login-config.xml file available in
name: name of the security domain [JBoss uses this name to generate a Jndi context with which it binds the security domain into JNDI]
login-module: login modules know how to load data from property files, database or an Ldap server for checking the credentials provided by the application. Code specifies the class of the login module implementation.
So now we have configured the security domain in login-config.xml file. Once this is done restart the server.
Not the final step, we will be using this security domain in our Datasource file, the code looks like this,
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->