Sunday, January 23, 2011

Setting Java System Properties in JBoss

I like using JVM system properties as a way to access non hard coded resources. Typing System.getProperty("myPropertyName") is convenient and clean. The best part is that these properties have JVM scope, so you don't have to worry about class loaders.

For convenience let me define a couple of variables:

%JBOSS_HOME= directory where JBoss is installed
%JBOSS_SERVER= server instance name

There are 2 ways to define system properties in JBoss:

a) By specifying them in %JBOSS_HOME/bin/run.conf

You use run.conf, don't you? Don't change run.sh or run.bat directly. That makes your application less portable. The file run.conf is used by run.sh or run.bat to setup a number of properties. To setup system properties you need modify the JAVA_OPTS variable. Find this section in run.conf and modify it accordingly:

#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms500m -Xmx500m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -DyourPropertyName=yourPropertyValue"
fi

As you can see I added the property yourPropertyName to the System Properties. So, once you restart the server, you will able to simply call System.getProperty("yourPropertyName") and get the value of it in any application running in JBoss.

The problem with this approach is that to change the values of the properties, or add values, you need to restart the server.

b) Use properties-service.xml

This is my favorite method. In $JBOSS_HOME/server/$JBOSS_SERVER/deploy you will find the file properties-service.xml . In this file you can specify new system properties, modify existing ones and even remove old ones. All you need to do is uncomment the following block in properties-service.xml:






yourPropertyName=yourPropertyValue



You don't need to restart the server for defined properties or changed in properties-service.xml to take effect. Placing properties with links to web services endpoints, LDAP servers and other resources in properties-service.xml makes an application EAR or WAR more portable and easier to move from a development environment to a production environment since the properties are outside of the deployment instruments.

Reference from: http://www.hugotroche.com/my_weblog/2008/07/setting-java-sy.html

Wednesday, January 12, 2011

JBOSS 5 on Java 5 Unsupported Operation...Set ....

from 5.0.0.GA
JBossAS 5.0.0.GA can be compiled with both Java5 & Java6. The Java5 compiled binary is our primary/recommended binary distribution. It has undergone rigorous testing and can run under both a Java 5 and a Java 6 runtime. When running under Java 6 you need to manually copy the following libraries from the JBOSS_HOME/common/lib directory to the JBOSS_HOME/lib/endorsed directory, so that the JAX-WS 2.0 apis supported by JBossWS are used:

* jbossws-native-saaj.jar
* jbossws-native-jaxrpc.jar
* jbossws-native-jaxws.jar
* jbossws-native-jaxws-ext.jar

Thursday, January 6, 2011

Linux change hostname

Display Hostname
Type the following command:

hostnameSample ouputs:

server.nixcraft.net.inStep # 1: Change Hostname
You need to update two files:

Linux Distribution specific file. Edit appropriate file as per your distribution as follows.
/etc/hosts
Redhat / CentOS / Fedora: Change Hostname
Edit /etc/sysconfig/network, enter:

vi /etc/sysconfig/networkSet HOSTNAME=newhost.example.com, enter:

HOSTNAME=server2.nixcraft.comSave and close the file. Type the following command:

hostname server2.nixcraft.com
hostname


Step #2: Update /etc/hosts
Now, you need to edit /etc/hosts file, enteR:

vi /etc/hostsChange all old hostname with newer one.