Wednesday, September 16, 2009

How a Single Character screwed my day!

In today’s Java world, we are so engrossed into using build & project management tools like ANT, MAVEN etc that we seldom use the atomic JDK tools(java,javac…) directly. Yesterday was one of those days when getting back to basics kicked my butt.
The Premise
  • Me and my colleague created a very simple MAVEN+SPRING project with a Main Class.
  • Used maven-exec-plugin to run the Main class and things worked perfectly fine
    • mvn exec:java -Dexec.mainClass="com.foo.MainClass"
  • Then came the primitive idea of using java to run the application with all the dependencies in the classpath. And we Java Junkies know it right?
    • java -classpath "x.jar;y.jar" com.foo.MainClass
The Problem
  • For some reason the primitive idea of using java tool didn’t work.
  • We stared at each other. Tried again. And again with quotes “”, other misc changes. But still didn’t work.
The Solution
  • Culprit (;)
    • All this was done on a Linux Dev machine and we forgot to realize that the character ‘;’ is recognized as some mumbo jumbo(which I haven’t figured out yet) by bash/shell.
  • Savior (:)
    • After hours (consider man minutes) of researching the on Google, Tech forums, etc with lame key words, I resorted to look into some preinstalled java apps on linux and there it was – the solution to the misery, the light at the end of the tunnel, the answer to the problem, a savior in the form of a single character ‘:
    • Just erased the presence of the culprit ‘;’ and replaced it with the lord, the savior ‘:’ and Voila!, Eureka!, …. IT WORKED.
    • java -classpath "x.jar:y.jar" com.foo.MainClass
Tip/ Note/ Realization
  • Understand the OS specific execution paradigms
  • The classpath delimiter in Windows is ‘;’ and in Unix flavors, it is ‘:
  • Revisit the basics often
  • Shit Happens
And this is how Ladies & Gentlemen, a single character screwed my day… and here is a single page documented (wasted) for that !!

No comments: