Showing posts with label JBoss. Show all posts
Showing posts with label JBoss. Show all posts

Wednesday, June 22, 2011

How to set jboss.server.log.dir in JBoss


Target audience: Beginners
Version: JBoss 4.2.x

By Default, JBoss writes the server log files to /jboss-4.2.0.GA/server/default/log location. We can change this location by specifying a system parameter jboss.server.log.dir .

For Example, if you want JBoss to write the server log file to “C:/Logs/JBoss/myapp”, then what you should do is to set a system property as this -Djboss.server.log.dir=C:/Logs/JBoss/myapp

As this property is used during bootstrap, this should be set when JVM starts. To do this, open “run.bat” file and set bellow entry. Remember to keep a space in front of %JAVA_OPTS%

set JAVA_OPTS=-Djboss.server.log.dir=C:/Logs/JBoss/myapp %JAVA_OPTS%
After setting this, start the JBoss server. you would see the log files would be created under “C:/Logs/JBoss/myapp

In the same way, you can set some other JBoss properties too. Some are given bellow

jboss.home.dir - The base directory of the jboss distribution - default: $JBOSS_HOME
jboss.home.url - The base url of the jboss distribution - default $JBOSS_HOME
jboss.lib.url - The url where the kernel jars exist - default: $jboss.home.url/lib
jboss.patch.url - A directory where patch jars exist - default: none
jboss.server.name - The configuration name of the server - default: default
jboss.server.base.dir - The directory where server configurations exist - default: $jboss.home.dir/server
jboss.server.base.url - The url where server configurations exist - default: $jboss.home.url/server
jboss.server.home.dir - The directory for the current configuration - default: $jboss.server.base.dir/$jboss.server.name
jboss.server.home.url - The url for the current configuration - default: $jboss.server.base.url/$jboss.server.name
jboss.server.temp.dir - The directory for temporary files - default: $jboss.server.home.dir/tmp
jboss.server.data.dir - The directory for data files - default: $jboss.server.home.dir/data
jboss.server.config.url - The url for configuration files - default: $jboss.server.home.url/conf
jboss.server.lib.url - The url for static jar files - default: $jboss.server.home.url/lib
jboss.server.log.dir - The directory where the server logs are written - default: $jboss.server.home.dir/log

Hope this is helpful for you.

Thursday, June 16, 2011

How to configure JBoss's log4j to log messages separately for different categories


Target audience: Beginners
Version: JBoss 4.2.x

We all know how to configure JBoss to log messages (DEBUG, INFO, WARN and ERROR) to a file. Let’s look at how to configure JBoss to log different categories to different files.

The configuration file can be found in [JBOSS]\server\default\conf\jboss-log4j.xml. Lets open the file. You will be able to see a default appender configure slimier to bellow

The above configuration to log the messages to a file ${jboss.server.log.dir}/server.log . And , we’ll sat that we have two categories are defined for logging the messages ${jboss.server.log.dir}/server.log

Currently all logs will be logged to "${jboss.server.log.dir}/server.log as we have configured in “FILE” appender.

Now we will configure the log messages of category “java.sql” to be logged in a different log file than the one already configured(“FILE”). Lest create another file appender configuration. We’ll name the appender as “FILE_SQL” and configure to log to ${jboss.server.log.dir}/server_sql.log

We have created the file appender and now we need to attach the category of which log messages should be logged to this file. The bellow configuration would do that.

After doing the above configuration,if you start the JBoss server and run your application, then all messages related to category “java.sql” will be logged in ${jboss.server.log.dir}/server_sql.log file.

Hope this note would be helpful for you.

Tuesday, July 13, 2010

How to use encrypted password in JBoss datasource


Target audience: Beginners
Version: JBoss 4.x

We configure the datasources in *-ds.xml files and place those files under \server\xxx\deploy location. The JBoss will scan any *-ds.xml under this location and create datasources.

I’m going to explain only how to use encrypted password in datasource configuration and i hope you all know how to configure the datasource. In this section, i going to configure a XA datasource with encrypted password.

JBoss provides a way to do configure datasource using encrypted password. The way is to use a “security-domain” property in the -ds.xml. This property should be mapped to a policy in login-config.xml under \server\xxx\conf location.

Look at the following sample -ds.xml files . I have commented out the section that are used when a clear text password is used.




XAOracleDS

false
oracle.jdbc.xa.client.OracleXADataSource
jdbc:oracle:oci8:@tc


OracleDSEncryptedLogon
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter


Oracle9i



name="jboss.jca:service=OracleXAExceptionFormatter">
jboss:service=TransactionManager




A “security-domain” property is defined(or mapped) with a value “OracleDSEncryptedLogon”. This “OracleDSEncryptedLogon” is called login policy and it should be defined in login-config.xml .
Ok, How do we define the login policy?. The bellow section shows how to defined a login policy in login-config.xml under \server\xxx\conf location.


.....





scott
5dfc52b51bd35553df8592078de921bc
jboss.jca:name=XAOracleDS,service=XATxCM






As you see, A “OracleDSEncryptedLogon” is defined with a user name and a password. The password is a encrypted password and it should be an encrypted password. The org.jboss.resource.security.SecureIdentityLoginModule is used as code. This org.jboss.resource.security.SecureIdentityLoginModule is a JBoss’s built in tool to encrypt and decrypt text.
Note: As i use XA datatsource, i have configured “managedConnectionFactoryName” module option with the jndi name “XAOracleDS” given in -ds.xml file and with the service “XATxCM”.

Ok, Now we know how to configure the encrypted password. But i think we have to encrypt the password . It can be done with the same jboss tool org.jboss.resource.security.SecureIdentityLoginModule. Follow the steps
Step 1.Open a command prompt
Step 2. Go to your JBoss home (C:/Tools/jboss-4.2.3.GA/)
Step 3. Set /bin to the path if it has not been set yet.
Step 4. Excecute bellow command to run the encryption tool to generate the encrypted password.

java -cp lib/jboss-common.jar:lib/jboss-jmx.jar:server/default/lib/jbosssx.jar:server/default/lib/jboss-jca.jar org.jboss.resource.security.SecureIdentityLoginModule password
you will see the
Encoded password: 5dfc52b51bd35553df8592078de921bc
Once you configured everything then just restart the server.
Hope this note will be helpful for you.

Saturday, July 10, 2010

How to use different deployment locations in JBoss


Target Audience: Beginners
JBoss version 4.x

We normally would have a build system which builds the application, creates the distribution files ( war, sar ,ear...) and then copies the distribution files to server/xxx/deploy directory. In JBoss, We used to deploy our applications under server/xxx/deploy.
E.g: D:/Tools/jboss-4.2.0.GA/server/default/deploy
Alternatively we can tell( configure) JBoss to deploy the application from our preferred location ( somewhere from outside of the JBoss).

How can we do that?
There is a MBean with name “jboss.deployment:type=DeploymentScanner” has been defined in conf/jboss-service.xml. This MBean is responsible for hot deployments. This MBean has a attribute “URLs” which accepts comma separated values. We can add our values too along with the existing values. Suppose our distribution files are built under c:/myproject/dist, then we can configure the DeploymentScanner as given bellow.


Don’t forget to restart the JBoss server after the changes were made. The DeploymentScanner will scan the configured URLs and deploy the possible applications.

If you want to configure the location without restating the application as hot deployment then you would have to do it through the JMX-Console. Please find the details here

Hope this will be helpful.

Tuesday, July 6, 2010

Binding JBoss to specific IP / configuring IP to JBoss application server


Target Audience: Beginner, Intermediate
When we configure the JBoss application in a production environment, the server need to be bind to an IP address ( in most cases). There are several ways to do it.
1. Setting as a run parameter. When we run the JBoss server in a cmd prompt, run as
run -b127.0.0.1

2. Setting it as a system property. We can set a system property which is used internally by JBoss server.
run -Djboss.bind.address=127.0.0.1

3. If we want the configuration to be permanent, then we can place the configuration inside run.bat file. Open run.bat file and search for org.jboss.Main and place the binding configuration .
E.g: org.jboss.Main -b192.168.5.29


Note: We can specify 0.0.0.0 if we want all IP addresses to be mapped to JBoss Server.

Friday, July 2, 2010

How to set System properties in JBoss


Target Audience: Beginners
Most of the times, we have to deploy our application in many environments for testing before going to production or live. We might have configuration values which need to be set in System Properties and these configuration might change based on the environment. We set System propertis in run.conf , run.sh or run.bat files with -D prefix
E.g: If we want to Set System property with key ‘myKey’ and with value ‘myValue” then we do something like JAVA_OPTS="XXXXXX -DmyKey=myValue.

JBoss give a rich way to load system properties. System properties can also be provided using the System Properties Service. This service allows you to specify one or more system propertis as key value pair or through loading one or more properties file. The Service configuration file can be found in the server/xxx/deploy/properties-service.xml.

The following section describes hoe to set one or more system properties as Key Value pairs.

<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
myKey1=myValue1
myKey12=myValue2
</attribute>
</mbean>

The Properties attribute section configures properties directly in the service
configuration. Properties must be specified as a name/value pair on a separate
line.

The following section describes hoe to set system properties through loading one or more files.

<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="URLList">
http://localhost/myapp-config.properties, ./conf/myweb-config.properties
</attribute>
</mbean>

The URLList attribute section refers to properties files that contain system properties.
You can provide a URL(http://localhost/myapp-config.properties) or a directory which is relative(./conf/myweb-config.properties) to the root of the server configuration.
Multiple entries should be separated with commas as shown above.

Hope this tutorial helps you.