Fun With Perl And Eclipse!

Apr 07, 2008 17:34

With the current project I am on, the build consists of a couple of steps:
1) Shutdown Tomcat
2) Run an ant script that does the actual compiling and putting things where they go
3) Startup Tomcat

(When I want to deploy changes that I just made to relatively static things, like Javascript files, I can just do step two)


When I started doing this, I used two command windows, one set to Tomcat's bin directory and the other set to the one where the buildfile lived. Then I discovered the joy of pushd and popd and was able to pare it down to one command window with the following:
(in Tomcat's bin directory):
%tomcat_home%\bin> shutdown
%tomcat_home%\bin> pushd %ant_buildfile_dir%
%ant_buildfile_dir%> ant dev_target
%ant_buildfile_dir%> popd
%tomcat_home%\bin> startup

Once I got that all on my history stack, I could just hit "down, enter" five times and it would redeploy everything for me. And yeah, I probably could have done it in three lines if I'd used a path to the buildfile in the ant command, but this worked reasonably well for me. But it was still kind of annoying to have to switch to Tomcat's bin directory and get it all set up, and if the history stack got corrupted by me doing anything else in that window, it took another bit of time (and was further annoyance) to get it back.

Wanting an excuse to learn a little bit about another programming language, and having heard good things about Perl, I wrote up two little scripts as an exercise. One of them runs the ant task with the target that I most often need it to run (it can be overridden by command line arguments)--it basically takes care of step two. The other one brings down Tomcat, executes the first script (passing along any command line arguments it received), and then brings Tomcat back up. I put them both in a directory on my path, and now I can run them from anywhere on the command line. It took some tweaking, but it's working great now and it was a fun exercise and I still get a little glow at having done it.

I very recently learned about Eclipse's "External Tools" ability, where you can have Eclipse run essentially any command line command. I've created two corresponding entries, one for each of the scripts, and also set up a keybinding to execute the most-recently-executed one. The only complaint I have about it is that I can't see the output of the ant script anymore in the one that also bounces Tomcat for me, and that's kind of important to be able to tell whether it was successful or not. Aside from that, though, it's great. I can run either of the scripts with either three or six keystrokes (three if it was the most recent, six if I have to switch to it first).

I think, at least in this case, that's the closest thing to instant gratification that I'm going to get ^_^

geek, eclipse, scripting, awesome, perl, computer geek

Previous post Next post
Up