Connecting the Microsoft Dots

When Win98 uptime was revealed to be never more than 49.7 days, Slashdot laughed. They could not imagine anybody actually wanting – or managing – to keep their Windows machine up for that long. I wonder if they would laugh now.

I wonder what other funny (WayBackMachine archive) Microsoft problems are going to bite us well after their discovery.

BlogicBlogger Over and Out

Troubleshooting ClassNotFoundException with Filemon (on Windows)

Have you ever run into classpath issues where you could have sworn the class was in a jar, the jar was on a classpath, yet you still got NoClassDefFoundError or ClassNotFoundException. Or perhaps you define several Classloaders in your application each with its own classpath and are not quite sure which one gets the priority in a specific situation.

On Windows, FileMon from SysInternals (FileMon from Microsoft now) is a great free tool to resolve exactly those kind of questions.

Imagine you have a very simple java class:

public class Test
public static void main(String[] args) throws Exception
Class c = Class.forName("somepackage.SomeClass");

Basically, we are trying to load somepackage.SomeClass into the system. For our test purposes that class does not exist.

Compile this class and run. It comes back with java.lang.ClassNotFoundException: somepackage.SomeClass. As it should.

The question however is what Classpath the JVM was looking for the class on. If your application is a J2EE deployment or anything with custom classloaders, this question may become a hard one to answer.

This is where the FileMon shines. FileMon will show you every file operation on the machine performed by any – or all – of the processes.

Start it up and set the filter to java.exe . If that causes problems you can reset filter to * and check what name your JVM is generating the log entries under.

With FileMon capture enabled, rerun your test or scenario. After you see the ClassNotFoundException, stop the capture. Now search from the capture start for the classname you got in the exception, in this case SomeClass. You should see a sequence of the lines similar to the following (some columns had been cut):

C:\temp\filemontest SUCCESS
C:\somepackage\SomeClass.class PATH NOT FOUND
C:\temp\filemontest SUCCESS
C:\Utils\somepackage\SomeClass.class PATH NOT FOUND
C:\temp\filemontest SUCCESS
C:\temp\somepackage\SomeClass.class PATH NOT FOUND
C:\temp\filemontest SUCCESS
C:\temp\filemontest\somepackage\SomeClass.class PATH NOT FOUND

From here, we can figure out that the classpath checked was: C:\;C:\Utils;C:\temp;C:\temp\filemontest.
Now, you can check that against your expectations and figure out how to fix the discrepancy.

If you are on Solaris/Linux machine instead, look into truss/strace for a way to achieve very similar results.

BlogicBlogger Over and Out

XMLStarlet: A gentle introduction into XSLT

In my work as a BEA Tech Support engineer, I have to spend a lot of time dealing with XML content. In the past I tried to grep through the files, but had found that element order and random newlines make it quite hard. I have since found a solution.

Everybody who works with XML probably knows that XSLT/XPATH is supposed to be a good way to manipulate XML files. Unfortunately, XSLT is very verbose and sometimes quite obscure, especially when it comes to plain text output. I have tried using it a couple of times and never got beyond a simple HelloWorld.

Then I discovered XMLStarlet. It is built on libxml2 and libxslt and is provided for several platforms as a all-in-one executable.

XMLStarlet has a number of options; among them are transformation, edit, canonicalization and many others. The one I find most useful is select. With select, XMLStarlet works something like an in-file unix find. You provide command line switches which describe what you are searching for and what you want to display.

And the best part of all is that the proprietary syntax translates into 100% correct XSLT, so when you have outgrown the tool or need more specific tweaking, you take the generated XSLT and start editing that directly.

Let me give you an example. I often have to work with Weblogic’s config.xml file which defines the configuration for a whole domain. It describes servers, clusters, JMSQueues, SecurityRealms and many more aspects. And, as config.xml was designed for the software’s convinience rather than support engineer’s, it groups elements together in a less than intuitive fashion.

Following, is a very small part of config.xml structure (derived from a sample config.xml file using XMLStartlet’s xml el -a config.xml command.


A task I need to do often is to check how many servers a client’s config.xml has, what their names are and how are they distributed between clusters. Manually, it means searching for <Server tag and then eyeballing for Name attribute.

With XMLStarlet it becomes:
xml sel -t -m //Server -v @Name -n config.xml
with the output of


In here, -m is match and -v is display. -n is a newline, not something that is obvious in XSLT itself. The parameters are XPATH values.

Do this 5 times and it pays back the time investment involved in learning the command syntax.

Now, let’s try to do something more complex. Specifically, I want to check which cluster each server belongs to. And to cut this post short(er), let’s say I want it sorted by the cluster.

The command would be:
xml sel -t -m //Server -s ATL @Cluster -v @Cluster -o " - " -v @Name -n config.xml
with the output of

- nhgprdadmin
cehs - nhgapp03a
cehs - nhgapp03b
cehs - nhgapp04a
cehs - nhgapp04b
his1 - nhgapp01a
his1 - nhgapp02a
his2 - nhgapp01b
his2 - nhgapp02b

We can immediately see that there is one non-clustered (admin) server, 4 servers in one cluster and 2 servers each in the other two clusters. In the command above, -s is sort by Cluster attribute and -o is verbose output used for spacing. Instead of -v -o -v, I could use -v "concat(XXX,yyy,ZZZ)", but that required a greater knowledge of XSLT than I had the first time I used the tool.

And just to show you the XSLT that the above command really corresponds to, it is (after removing long header and footer):

<xsl:template match="/">
<xsl:call-template name="t1"/>
<xsl:template name="t1">
<xsl:for-each select="//Server">
<xsl:sort order="ascending" data-type="text" case-order="upper-first" select="@Cluster"/>
<xsl:value-of select="@Cluster"/>
<xsl:value-of select="' - '"/>
<xsl:value-of select="@Name"/>
<xsl:value-of select="'

As you probably can imagine, it takes quite a bit longer for an XSLT beginner to write the code above from scratch.

I hope this was useful and will convince you to have a look at the XMLStarlet.

BloggicBlogger Over and Out

> From inner thoughts to outer limits of Alexandre Rafalovitch