Monday, 19 November 2012

Configuring static resources for use within the application in JBoss AS 7

In previous versions of JBoss, you could link an external directory into the classpath and load static resources like images/CSS/JS into the application using the WEB-INF/context.xml

<Context allowLinking="true" cookies="true" crossContext="true" override="true"> 
<Resources allowLinking="true" homeDir="/mydomain/staticfiles" /> 

In Weblogic servers, there is the virtual-directory-mapping to achieve this.

In Jboss 7 this no longer works, and you need to bundle the static files within the EAR or War. Note: If you need to serve these over the browser like a public web server as static files then you need a servlet method like this

But if you want to load a static property file or other content into your webapp, the solution provided by Jboss is what this post is about. You can define a “module” within JBOSS_HOME and store the files there or extend that to any location on the filesystem.

The base reference for this solution is on the Jboss forums How to put an external file in the classpath

Please read that for the theory behind this. Actual steps to be used to store and load any static files or properties or config etc:

1. Create a new module for your configuration or static files - at this location


<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.1" name="com.mycompany"> <resources> 
<resource-root path="."/> 

2. Add your properties files or images to the module at this location








3. Add your module to your application classpath in a jboss-deployment-structure.xml file

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure> <deployment> <dependencies> 
<module name="com.mycompany" />

This file must be placed either in the META-INF directory of your EAR file or the WEB-INF directory of your WAR file. See Class Loading in AS7 for more information.

OR add your module to your application classpath using a MANIFEST.MF entry in the META-INF of the EAR

Manifest-Version: 1.0

Dependencies: com.mycompany

5. Load a properties file from the classloader in your application

URL imgUrl = this.getClass().getClassLoader().getResource("logo.jpg");

As you’ve noticed this sits within the JBOSS_HOME/modules directory. You can further change the location of this by editing the standalone.bat or files as follows



"-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^

"-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/" ^

-jar "%JBOSS_HOME%\jboss-modules.jar" ^

-mp "%JBOSS_MODULEPATH%;d:\mycustommodules" ^

-jaxpmodule "javax.xml.jaxp-provider" ^ ^

-Djboss.home.dir="%JBOSS_HOME%" ^


And the corresponding structure on Windows platform looks like this







In this way your static directory does not need to be within the JBOSS folder at all.

Friday, 26 October 2012

A Brief Encounter with Cyanogenmod 9 on the HTC Wildfire

I’ve been using CyanogenMod 7.2 quite happily since the last few months on Wildfire A3333. I recently tried to connect the stock Email application to a Microsoft Exchange 2010 server for my corporate Email.

When setting up the mailbox and accepting all SSL certificates and seting up a Password/PIN I still get the error

"This server requires security features your phone does not have"

This primarily seems to be because Android 2.x does not have this flavour of encryption – “full Storage card encryption”

This has been provided in Android 3.0 and in ICS 4.0 onwards for handsets

The relevant documentation is at

So I decided to upgrade to CM 9 for Wildfire and see where it takes me.

First and most importantly – do a Nandroid back up of the existing ROM and settings. You’ll revert to the backup many times. Also export phone contacts to a file which you will need to re-import later.

The version of CM 9 I used can be downloaded from here

After installing CM9 – the first impression was a neat boot logo which plays for the 3 minutes or so it takes to boot up the phone.

After that the phone was really really slow. The default launcher to show all apps and Dialer take over 5 seconds to respond.
Seems like the A3333 is just not cut for this ROM due to having only a single core CPU. Any reboot of the phone always takes over 3 minutes.

I tried using the Zend Launcher instead of the default Trebuchet and exDialer instead of the Stock dialer. This made these 2 functions much faster.

Also uninstalled some apps using the Solid Explorer. Some of the features were good - like longpressing an app allows it to send a shortcut to Home screen.

I tried encryption which I knew will slow down the phone even more. Most forums say this takes a long time, so I left it overnight with the charger plugged in.

I tried this process twice, and it still would always show the In Progress screen for encryption and not complete this even after taking 10 hours uninterrupted.

I followed the steps at How to encrypt

So finally I had to give up encryption, and revert the ROM to the backed-up CM 7.2

Using CM 9 gave me some neat apps which I now installed on 7.2

First, I didn’t like the Gallery app in 7.2 (it shows zoom buttons instead of pinch to zoom) so updated that with QuickPic
I also installed Solid Explorer which allows removal of apps even from /data/app and /system/app instead of File Manager.

Tuesday, 4 September 2012

Solution for Win XP 0xc0000218 {Registry File Failure} The registry cannot load the hive

So my 9 year old Dell Inspiron 510m laptop running Windows XP Service Pack 2 crashed last week with a Blue Screen of Death (BSOD) message.

Stop: 0xc0000218 {Registry File Failure} The registry cannot load the hive (file): \SystemRoot\System32\Config\System or its log or alternate. It is corrupt, absent, or not writable.

Rebooting in safe mode doesn’t work.

Rebooting after running Full Diagnostics doesn’t work, the laptop is always stuck with this failure.

The Microsoft link is a good starting point but I tried many things to finally get it working, so actually this article is also a Solution (rather a Workaround) for the following other errors that you may face:

Windows XP not accepting the Administrator password in Recovery Console

Windows XP Setup stuck at License Agreement – F8 key not working

So the sequence of events, trials and failures are as follows – these may help you in the future.


Trial 1:  Run the Recovery Console from the Windows Setup CD to fix the system

If you have the setup CD, then rather than formatting the whole drive, you could attempt a recovery using the setup. In this way, you will still be left with your settings and files intact.

Now when you try this, you see a screen as below asking for the Administrator password.

But you don’t remember your Admin password – or like me you swear you never set an Admin password at all – so you leave it blank and press <Enter>.

You get a message saying the password is invalid. This goes on for 3 attempts and then you have to exit the recovery.

Some links state that Dell laptops are preloaded with sysprep which requires you to set a password on first usage, but it’s been so long I don’t remember doing that.

I also tried rebooting with F2 into the BIOS and scrolling to the page on which quite clearly it says

Administrator Password: DISABLED

So I ENABLE it and try setting one of those, save the settings and try the recovery again. And again. And again.

It still doesn’t work.


Trial 2: Attempt to recover the admin password as part of a Repair of Windows from the Installation CD.

This link mentions a technique by which you can run the Setup and then choose Repair and then get access to User Accounts in the Control Panel.

So only one problem in this approach – while trying the Setup you reach this step.

When you get to the Welcome to Setup screen, press ENTER to Setup Windows now

The Licensing Agreement will come next - Press F8 to accept it

But when I try to press F8, nothing happens. It just stays there. All other keys work such as PageUp, PageDn and Esc to quit.

So the things to try at this point are use Function key Fn + F8 together. Doesn’t work.

Try all other F keys from F1 to F12, with and without Fn key. None of them work.

For good measure, try Fn + 8 rather than F8. Nope.

Try almost all other keys on the keyboard (except Esc).  Try all of them with Shift, Ctrl or Alt. Try all of them with NumLock on and off.

After all of these fail – try plugging in an external USB keyboard. Many sites says the PS/2 keyboard works, but of course this laptop does not have the PS/2 connector port.

Try BIOS options to change the F8 key, didn’t see any such options.


Trial 3: Recover the data from the hard disk first and overwrite the corrupted Hive files. [SOLUTION]


At this point, I got myself an IDE adapter casing with a USB cable. I removed the Hard drive from the laptop and was able to copy over all my data onto another PC.

Manual Recovery of Windows registry, c:\windows\system32\config\system - software, or corrupt hive file or hal.dll errors with no CD.


Now that I had the original hard disk connected as an external hard drive (connected as G:\) , I went into an earlier System Restore point using the cmd prompt.

From the snapshots available on the disk, back up and then copy the software, system, sam, security and default files over as per the Microsoft list at   
Note: G:\ is the original laptop hard drive now connected via USB

copy _registry_machine_software g:\windows\system32\config\software

copy _REGISTRY_USER_.DEFAULT g:\windows\system32\config\default

copy _REGISTRY_MACHINE_SECURITY g:\windows\system32\config\security

copy _REGISTRY_MACHINE_SYSTEM g:\windows\system32\config\system

copy _REGISTRY_MACHINE_SAM g:\windows\system32\config\sam

Once all the copies were done, I fitted the drive back into the laptop and it booted up normally.


Tuesday, 28 August 2012

How to check if HTC Wildfire is rooted

I noticed some posts asking to know if HTC A3333 is already rooted.

2 easy ways:

1. Presence of the Superuser app

Superuser comes pre-installed on any rooted ROM. In fact, without it, you don’t have a rooted device at all. You cannot uninstall it, it lives on the system partition with other apps that came pre-installed on your device.

2. Open the Terminal Emulator and type "su"

This will request for root access IF you are rooted

Another option is to download Root Checker from the market it will tell you if you have root

Friday, 24 August 2012

Identifying memory leaks using Eclipse MAT - Part 3

So back to finding out what this class weblogic.xml.query.xdbc.Context  was and how we could solve the memory leak.

A quick search in Eclipse showed this class gets loaded from com.bea.core.xquery_1.3.0.0.jar and the Eclipse calling trace showed a call to$CompiledQuery.


We knew we are using apache xmlbeans in our application and checked our Weblogic start classpath to see this jar had been added to the classpath since we had some runtime issues without it.


But we did not want to use the weblogic version of xmlbeans, so only tried with the Apache one instead.

So the changes made were to remove the above jars from start classpath and add saxon jars instead. We also edited weblogic-application.xml to specify the package from Apache


We then repeated our performance tests and monitored the heap dumps to verify the problem had gone away.

There was no instance of the weblogic.xml.query.xdbc.Context class at all which caused earlier heap block, so this indicates our fix is applied correctly

Thursday, 23 August 2012

Identifying memory leaks using Eclipse MAT - Part 2

As I wrote in Part 1, we identified that there was some sort of memory leak happening within our Java JEE application – so the next steps were to obtain a Heap Dump and run it through Eclipse MAT.

So what is a Heap Dump? From the Eclipse docs

A heap dump is a snapshot of the memory of a Java process at a certain point of time. There are different formats for persisting this data, and depending on the format it may contain different pieces of information, but in general the snapshot contains information about the java objects and classes in the heap at the moment the snapshot was triggered.
The Memory Analyzer is able to work with HPROF binary heap dumps, IBM system dumps (after preprocessing them), and IBM portable heap dumps (PHD) from a variety of platforms.

Typical information which can be found in heap dumps (once more - depending on the heap dump type) is:

  • All Objects
Class, fields, primitive values and references
  • All Classes
Classloader, name, super class, static fields
  • Garbage Collection Roots
Objects defined to be reachable by the JVM
  • Thread Stacks and Local Variables

How do we get a heap dump into a .hprof file?

Set the following flags to the java process

·        -XX:+HeapDumpOnOutOfMemoryError writes heap dump on OutOfMemoryError

·        -XX:+HeapDumpOnCtrlBreak writes heap dump together with thread dump on CTRL+BREAK

Or you can fire one via tools jmap or jconsole

·        Sun JMap: <jdkhome>/bin/jmap  -dump:format=b,file=HeapDumpFilename.hprof


Our idea was to take multiple heap dumps every 2 hours or so and observe the objects in the heap. As with a thread dump, a heap dump is a static view of the live objects in the heap at that time – so it’s not possible to make a definitive judgment on just viewing one heap dump – hence space it out over some time and observe if the same objects (sometimes these have the same memory address location) are growing and causing a possible leak.

Also remember – at the point of taking a heap dump, Java runs a full GC, so you are left with the live objects in the heap.

We took the first heap dumps every 2 hours, but nothing much was happening for the first 12 hours or so.

Once you have the hprof with you, and have installed Eclipse Memory Analyzer Tool (MAT) just open the hprof in Eclipse and wait for it to do it’s thing.

The page will open with an Overview.

This lists important stuff like the Size of the heap – so in our case, though we have a 2 GB heap the retained size after GC is 473.1 MB.

The graph of “Biggest Objects by Retained Size” will give you immediate clues and this is also reflected in tabular format in the “Dominator Tree” report.


But the best thing about MAT is the Leak Suspects report which points out clearly potential memory leaks.



So in our hprof, 55% of the heap was being retained by one instance of weblogic.xml.query.xdbc.Context i.e. if this object was reclaimed by GC, we could get back 273 MB of memory. This object was residing at memory location weblogic.xml.query.xdbc.Context @ 0xb2477930
The important thing to see in this view is the Retained Heap
In Memory Analyzer the term shallow size means the size of an object itself, without counting and accumulating the size of other objects referenced from it.
The retained heap is the total objects and memory which this object is holding onto.


We took the next snapshot after 2 hours of the first heap dump and it showed the same instance of weblogic.xml.query.Context@0x7c1642f8 had now grown to 301.6 MB with the total heap now at 524.7 MB

Our last snapshot in confirming our problem was after a further 2 hours, so a total of 4 hours since the first heap dump showed this object.

The heap had now grown to 616.5 MB with 54% of it occupied by the same object
So next we now found out from MAT what was causing the leak. We next had to analyze how this class weblogic.xml.query.xdbc.Context  was being used in the app and how we could prevent the leak. I will post that in Part 3.

Saturday, 28 July 2012

JVM Heap analysis – Identifying memory leaks using Eclipse MAT

As part of the regular pre-Production testing it is common to conduct Performance tests for load under Peak and Soak conditions.

So we had this Weblogic platform on which all Peak tests were good and so also were the 12 hour Soak tests.

The JVM memory usage graph plotted showed regular GC clearing up memory and no obvious leaks. A simple graph plotted in Excel showing JVM Used Heap over time is shown below. It shows the pattern fairly close to an ideal sawtooth.

An additional test planned was an Extended Soak – mainly letting the system run as per expected normal volumes over 7 or 10 days to see if the JVM would throw up any unusual memory usage patterns or memory leaks.

And we came across some interesting issues !!

We did not have much of a problem for the first 24 and 48 hours – but after 48 hours (2 whole days) of continuous load, the graph showed that the JVM was unable to clear up any memory even after GC.

As the graphs above show the Weblogic server JVM inspite of multiple GCs was not reducing the utilized memory down to the usual 30 - 40% or so. It was staying at 80% or so until after 7 days the servers went OutOfMemory and just crashed.

So in order to analyze this we decided to take JVM Heap Dumps and analyze this using VisualVM or Eclipse MAT.

In this instance Eclipse MAT which is an easy Eclipse plugin gave an instant feedback and we were able to narrow down on Leak Suspects and actually find the root cause of the problem.

I will elaborate on that in Part 2 of this series.

Monday, 30 April 2012

Installing multiple external jars into a local maven repository.

Suppose you have a variety of dependency jars you need to install into your local repository - Note: These arent artefacts produced by your build but external jars. Well, no shortcuts here. From a recent reply I gave on Stackoverflow - You'll have to do it via a script, the long and boring way. This is what we use - modifying the values in each of the `set` statements
    set GROUP_ID=someNamespace
    set ARTIFACT_ID=myartifact
    set VERSION=1
    set FILEPATH=D:\my.jar
    call mvn install:install-file ^
     -DgroupId=%GROUP_ID% ^
     -DartifactId=%ARTIFACT_ID% ^
     -Dversion=%VERSION% ^
     -Dfile=%FILEPATH% ^
     -Dpackaging=jar ^
    set GROUP_ID=someNamespace2
    set ARTIFACT_ID=myartifact2
    set VERSION=1
    set FILEPATH=D:\my2.jar
    call mvn install:install-file ^
     -DgroupId=%GROUP_ID% ^
     -DartifactId=%ARTIFACT_ID% ^
     -Dversion=%VERSION% ^
     -Dfile=%FILEPATH% ^
     -Dpackaging=jar ^

Tuesday, 10 April 2012

Rooting HTC Wildfire and installing Cyanogenmod

There are many guides out there, this is a diary of events and some errors you might run into and resolutions which worked for me.

Phone Model HTC Wildfire A3333 running on Android 2.2.1 (Froyo)

Began with HBOOT 1.01.0002

Note: To find your HBOOT version -

Switch the phone off, then hold the volume down button and while holding press the power button. At the top of the screen it will show the HBOOT version. To exit this screen, press the power button to select fastboot and then use the volume down to select reboot.

The One-click guide given at did not work initially.

It ran successfully up to step 11 out of 11, when running Revolutionary it gets to a screen on the tool with the message stuck at "Waiting for device"

So I had to do this the older way downgrading to HBOOT 1.01.0001 followed by switching the phone to S-OFF mode

The complete guide which works for me is this one

Further errors that appear along the way and their solutions:

1. Revolutionary stuck at "Waiting for device"

The solution which worked after consulting various forums, was to install latest version of HTC Sync on the PC and then uninstall it, leaving the HTC Drivers on the PC.

Under Control Panel > Add/Remove Programs you should see the HTC drivers shown in the image below.

2. After this it proceeds to the point where Revolutionary says "Waiting for root"

This takes forever and does nothing.

Of course this is because I thought one of the steps was optional - that of downgrading from Froyo(2.2.1) to Eclair(2.1). Turns out, I do need to do that - once that is done, Revolutionary goes ahead and gives the Success message.

3. After that you can install Cyanogenmod. Ensure you install and not 7.1.0.

7.1.0 is buggy and as soon as the phone reboots, it gives a "Force Close" message with no status / notification bar. It also does not show any incoming phone calls - you can hear the ringtone but there is not way to accept the call.

All of this is fixed in which is downloadable as

After that, surprise surprise, there's no GMail, Market or Maps. These are not part of Cyanogenmod. These are available as a separate zip from

I used for Wildfire but still had to install Google Maps separately from the Market.

After this, I uninstalled some of the apps I didnt want to use in the Cyanogenmod ROM.

A list of what is safe to remove and what is not is given at the

Cyanogenmod wiki at

Follow the instructions and play around with it.

I later upgraded to CM 7.2 using this ROM from here

For those used to HTC's Predictive Dialer, the native CM one kind of sucks. Use the Touchpal Contacts smart dialer app from the Market.

With 7.2 I've seen my battery charges quicker than before (with HTC ROM) and the interface is much quicker too.

Dont' forget to add some Lockscreen Gestures

More cool things to do are here

Additional reference links:

Wednesday, 4 April 2012

Weblogic - Accessing Server Runtime details using JMX

We had a requirement to access certain runtime info on the Weblogic server to carry out some admin tasks.

One way to do this is via the JMX API, which in Weblogic is available as an extensive set of MBeans

There are plenty of tutorials and examples of using these on the net.

Now within your Weblogic domain, if you run as part of a Cluster then you would access Domain information on the Admin server if you need to identify the running servers in the cluster.

This uses
object which is bound only on the Admin server.
One full example of this is at

If you try this on a managed server directly, you will get this error Unable to resolve ''. Resolved ''

So if you do not have the Admin server IP address and port, how can you still identify the other members in the cluster?

A use case for this is if you want to run and access Cluster details from one of the managed servers. But you only have the current running server IP and Port and not that of the Admin server - which is usually the case

There is an MBean for this which is available on the individual managed server as well,

Using this you can get the details of the Admin server and then from there get access to the DomainRuntimeServiceMBean.

A working code example is below

This runs from a JSP where we are able to access the server IP and port via request variables

<%@page import="javax.xml.bind.DatatypeConverter"%>
<%@page import=""%>
<%@page import=""%>
<%@page import="java.util.Hashtable"%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import="javax.naming.Context"%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import="sun.misc.BASE64Encoder"%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import="javax.naming.InitialContext"%>

 MBeanServer mBeanServer = null;
 InitialContext ctx = null;
 String administrationURL = null;
 int adminPort = 0;
 try {
  ctx = new InitialContext();
  mBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
  //Get Admin Server and Port
  ObjectName runtimeService = new ObjectName(
  String managedServerName = (String) mBeanServer.getAttribute(runtimeService, "ServerName");
  ObjectName msServerRuntime = new ObjectName("com.bea:Name="+ managedServerName + ",Type=ServerRuntime");
  administrationURL = (String) mBeanServer.getAttribute(msServerRuntime, "AdminServerHost");
  adminPort = (Integer) mBeanServer.getAttribute(msServerRuntime, "AdminServerListenPort");
  System.out.println(administrationURL + adminPort);
 } catch (Exception ex) {
  System.out.println("Caught Exception while fetching Admin Server information : "+ ex);
 } finally {
  if (ctx != null) {
   try {
   } catch (Exception ex) {

 //Connect via JMX using Admin Server credentials
 String protocol = "t3";
 Integer portInteger = Integer.valueOf(request.getServerPort());
 int port = portInteger.intValue();

 String jndiroot = "/jndi/";
 String mserver = "";
 JMXServiceURL serviceURL = new JMXServiceURL(protocol, administrationURL, adminPort, jndiroot + mserver);
 Hashtable h = new Hashtable();
 h.put(Context.SECURITY_PRINCIPAL, weblogicuser);
 h.put(Context.SECURITY_CREDENTIALS, weblogicpassword);
 JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
 MBeanServerConnection connection = connector.getMBeanServerConnection();

 ObjectName domainRuntimeService = new ObjectName(
 ObjectName[] serverRT = (ObjectName[]) connection.getAttribute(domainRuntimeService, "ServerRuntimes");
 Hashtable server_states = new Hashtable();
 for (ObjectName ser : serverRT) {
  server_states.put((String) connection.getAttribute(ser,"Name"), (String) connection.getAttribute(ser,"State"));

 ObjectName domain1 = (ObjectName) connection.getAttribute(
    domainRuntimeService, "DomainConfiguration");
 ObjectName[] cluster_list = (ObjectName[]) connection
    .getAttribute(domain1, "Clusters");
 for (ObjectName cl : cluster_list) {


 Cluster Name: "
    + (String) connection.getAttribute(cl, "Name"));
  try {

   ObjectName[] servers = (ObjectName[]) connection.getAttribute(cl, "Servers");
   for (ObjectName ser : servers) {
    String server_name = (String) connection.getAttribute(ser, "Name");
    try {
     String server_URL = (String) connection.getAttribute(ser, "ListenAddress");
     Integer server_port = (Integer) connection.getAttribute(ser, "ListenPort");
     System.out.println("Server Name: " + server_name + ", Server State: "
        + server_states.get(server_name)
        + ", :" + server_URL + ":"
        + server_port);