tools of the trade

Don’t get me started on EJB.

Anyway, I had a problem where a jboss.xml has a resource reference that is missing from its matching ejb-jar.xml. Visually scanning the files wasn’t getting me anywhere, since they contain at least 30 EJBs, of which 20 or so had the same resource reference in.

I thought if they were text files, I might use the shell tools I am used to, grep for example. But these are XML files, and therefore need parsing. I realised if I could easily apply an XPath then I could get the information I wanted.

Ah, XSLT is usually used to transform XML into other XML, but it can just as easily print out text lines. I can use xsltproc to spit out the details I want, on the command line. A bonus is that it can sort the results.

<xsl:stylesheet version="1.0">
<xsl:template match="/">
<xsl:for-each select="(//session | //entity | //message-driven)[resource-ref/res-ref-name = 'jdbc/DataSource']">
<xsl:sort select="ejb-name">
<xsl:value-of select="ejb-name"><xsl:text>

The files I’m interested in have a similar structure, so this works against both. I just have to run

xsltproc testdatasource.xsl ejb-jar.xml


xsltproc testdatasource.xsl jboss.xml

and compare the output.


Post a Comment

Your email is never published nor shared. Required fields are marked *