Keeping It DRY - Automation of Repetitive Tasks
I’m woking on a “legacy” Java app that’s written in Struts and uses EJBs. No Jetty or Tomcat for me - gotta use a “real” J2EE container - in this case, JBoss.
Unfortunately, I haven’t figured out a good way to run JBoss against my sources, as I would if using something like the jetty or tomcat plugins for maven. So I find myself redeploying the app frequently when working on the UI.
Of course, JBoss is only good for a handful of redeployment cycles before it goes four paws up with a “java.lang.OutOfMemoryError: PermGen space” error. And when it does this, the processes must be killed. On Linux, this involves doing a “ps” command to find the process ids, and then using the “kill” command to kill them. Easy stuff, but very repetitive.
I’m a big fan of the “Pragmatic Programmer” Series of Books, so I quickly thought of the “Don’t Repeat Yourself” (DRY) principle put forth there.
The result? A simple shell script for killing JBoss:
ps -ef | grep jboss | grep -v grep | awk '{print $2}' | xargs kill -9