Java snippet: Debugging a Java library used from Ant
I recently needed to debug a library which seemed to be misbehaving when used within Ant. After a bit of research here’s the best way I found to debug within Ant that doesn’t require sprinkling your bin/ant or bin\ant.bat with temporary JPDA pixy dust.
Ant doesn’t directly accept the -X arguments needed to set up the JPDA settings so the question is: how do you pass these from a shell or command line? In this, the ANT_OPTS environment variable is your friend. Its contents will be directly passed to the Java process Ant calls.
So here’s how you do it:
Step 1: Set ANT_OPTS to the debug options appropriate for your JVM:
for Java 1.4:
>> export ANT_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453
for Java 1.5:
>> export ANT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8453
Step 2: Run ant like normal:
>> ant
Step 3: Set your breakpoints.
Step 4: Now attach your debugger.
There might be better ways to do this but this was the least invasive route for me.
Challenges - knowing when to say no 1
Many dynamic and energetic developers I have known share a characteristic of reflexively accepting the challenges put to them by their organisation. I think many people are just wired that way - they are presented with a challenge and their sense of self worth or their desire to please or whatever it is compels them to accept it; and beat it.
What do you do when the challenges are nonsensical, not worth doing or based on clearly broken assumptions. In a ‘can do’ culture that places a high value on ‘being pro-active’ a challenge can often take on mystical properties that make it unasailable and immune to rational questioning or discourse. If it was uttered thus must it be worthwhile.
It takes a lot of guts to say to someone (especially someone you report to or someone in a position of substantial power) “your challenge doesn’t make sense, I refuse to accept it”. In such organisations rejecting a challenge is often worse than failing the challenge itself and you may run the risk of being labeled a recalcitrant, nay-sayer, lazy or worse.
If a friend came to you and challenged you to invent a perpetual motion machine, would you accept or reject the challenge? Kooks aside, most of us would reject it and we wouldn’t judge ourselves by the standards of the challenger - we’re not failures because we refuse to invent a perpetual motion machine. We know it’s sheer folly.
Organisations should do the same when they’re forced to into a Mythical Man Month scheduling ‘challenge’ by overzealous upper management eager to make their mark. Adding manpower to a late (or tight) project will just make it later (or tighter) and we shouldn’t be afraid to rebuff a challenge to come up with aggressive project plans based on the assumption that “men and month are interchangeable”. This, too, we know is sheer folly.
Technorati Tags: development, management, Mythical Man Month, projects