Simplified CLI use of YUI Compressor

Let me start by saying I’m not a java guy, “my understanding of java is based on experience, and may be somewhat flawed”…[*][]

I’ve squeezed as much as I can from jsmin. I need to play with the big boy toys so I finally installed YUI Compressor. But not being a java guy I found it’s command line use a bit cumbersome:

$ java -jar /path/to/class/yuicompressor.jar [options] [input] [output]

At the very least I wanted something more like this (with yuicompressor.jar being in my $PATH):

$ java -jar yuicompressor.jar [options] [input] [output]

So, having added the yuicompressor.jar to my `/usr/local/bin/java` directory, I set about adding two new paths to the $CLASSPATH environment variable in my .bash_profile, to find both classes and jar files (so I thought, see disclaimer):

export CLASSPATH="${CLASSPATH}:/usr/local/bin/java/*:/usr/local/bin/java"

Not really sure where I went wrong, but regardless this failed (or more correctly, I failed).

It was at this point that [@therealjaypo][] tipped me off that, “-jar relies on the launch metadata inside the jar. If you find the class it invokes, you can use [$CLASSPATH]”. Ok, cool so now instead of `$ java -jar /path/to/class/yui…` I could just use `$ java…`. Things were getting so much… easier?

Then [@therealjaypo][] hit me with the giant stick of obvious, “That’s why the FSM invented ‘alias’ :)”.


So back to the .bash_profile to add this line:

alias yui='java'

Now using YUI Compressor is as easy as any other command line app in my $PATH:

$ yui [options] [input] [output]