Saturday, June 30, 2012


Recently I needed to use NetBeans to work on a project that needed HTTP access to a set of static files. The way I did it was to edit the embedded Tomcat server.xml like so:

    <Engine defaultHost="localhost" name="Catalina">
        <Realm className="org.apache.catalina.realm.LockOutRealm">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
        </Realm>
        <Host appBase="webapps" autoDeploy="false" name="localhost"
              unpackWARs="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve"
                   directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b"
                   prefix="localhost_access_log."
                   resolveHosts="false" suffix=".txt"/>
            <Context path="/sdk" docBase="z:/Data/Foo" />
            <Context path="/web" docBase="z:/web" />
        </Host>
    </Engine>

Enjoy!

Saturday, June 23, 2012

HowTo - get directory of executing bash script

    BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

HowTo - read a value from a Java Properties file in Bash

    # Reads property $2 from properties file $1 and echos the value. To call this method do:
    #
    #     V=$(getProp filename property)
    #
    function getProp () {
        # ignore lines with '#' as the first non-space character (comments)
        # grep for the property we want
        # get the last match just in case
        # strip the "property=" part but leave any '=' characters in the value

        echo `sed '/^[[:space:]]*\#/d' $1 | grep $2  | tail -n 1 | cut -d "=" -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//'`
    }

Friday, June 8, 2012

Difficult Tasks

This is what is meant by "pulling a Brave Sir Robin" when assigned a difficult task... for the curious people.

Brave Sir Robin

Brave Sir Robin Ran Away
Bravely ran away away
When danger reared its ugly head
He bravely turned his tail and fled
Yes Brave Sir Robin turned about
And gallantly he chickened out
Bravely taking to his feet
He beat a very brave retreat
Bravest of the brave Sir Robin