Erik Beeson http://blog.erikandcolleen.com Most recent posts at Erik Beeson posterous.com Sun, 07 Aug 2011 03:06:00 -0700 Single Webapp Jetty 7 Configuration http://blog.erikandcolleen.com/single-webapp-jetty-7-configuration http://blog.erikandcolleen.com/single-webapp-jetty-7-configuration

When developing a webapp in Java, I prefer to use Jetty when possible. While it’s easy enough to drop an exploded war into the webapps directory, often I want the app hosted at the root without all of the extra options that Jetty includes by default.

With a simple XML configuration, this is pretty straightforward to do. First, get Jetty (I’m using the latest stable of version 7):

$ wget -r -nc -np -nd -A zip "http://download.eclipse.org/jetty/stable-7/dist/"
$ unzip jetty-*.zip
$ rm jetty-*.zip

Then download this config file to the Jetty directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.server.Server">
<Set name="connectors">
<Array type="org.eclipse.jetty.server.Connector">
<Item>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set>
</New>
</Item>
</Array>
</Set>

<Set name="handler">
<New class="org.eclipse.jetty.webapp.WebAppContext">
<Arg><SystemProperty name="webapp" default="../webapp"/></Arg>
<Arg><SystemProperty name="webapp.context" default="/"/></Arg>
</New>
</Set>
</Configure>

$ cd jetty-*
$ wget "https://raw.github.com/gist/1130234/638e7405f901b378bb8daa18ef1d81fabc9023de/jetty-single-webapp.xml"

By default, Jetty will include a number of additional config files. To ignore them, an empty --ini= parameter is required, like so:

$ java -Dwebapp=/path/to/webapp -jar start.jar --ini= jetty-single-webapp.xml

Note the space directly after --ini=

The config file refers to 3 properties: jetty.port, webapp, and webapp.context.

  • jetty.port: the port to which the HTTP server is bound.
  • webapp: the filesystem path, relative to the Jetty directory, that will be used as the root of the webapp (defaults to “webapp” next to the Jetty directory).
  • webapp.context: the base context path where the webapp will be published (defaults to “/”).

That’s all there is to it. With this it’s easy to host different apps by changing the webapp property or run multiple apps with multiple Jetty instances (on different ports with the jetty.port property), plus Jetty starts up quicker without the extra options.

Permalink

]]>
http://files.posterous.com/user_profile_pics/1326808/Erik_Profile.png http://posterous.com/users/hcH2JKRhUmEqK Erik Beeson erikbeeson Erik Beeson
Fri, 15 Jul 2011 00:33:00 -0700 Quick & Easy random.org on OS X http://blog.erikandcolleen.com/quick-easy-randomorg-on-os-x http://blog.erikandcolleen.com/quick-easy-randomorg-on-os-x

Previously I shared a quick and easy app for generating a random string into the clipboard, based on /dev/random.

But what if we wanted true random?

By leveraging the random.org api this turns out to be almost as trivial as the previous version:

1
set the clipboard to (do shell script "echo `curl -s \"http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=off&loweralpha=on&unique=on&format=plain&rnd=new\"``curl -s \"http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=off&loweralpha=on&unique=on&format=plain&rnd=new\"`")

With the addition of an icon (based on the random.org logo font) we have Random String.app:

Download Random String.app

Be away that random.org has daily quota restrictions, so if you use it a lot be sure to keep an eye on your quota.

Permalink

]]>
http://files.posterous.com/user_profile_pics/1326808/Erik_Profile.png http://posterous.com/users/hcH2JKRhUmEqK Erik Beeson erikbeeson Erik Beeson
Tue, 05 Jul 2011 21:50:00 -0700 Quick & Easy Random Alphanumeric on OS X (w/ AppleScript) http://blog.erikandcolleen.com/quick-easy-random-alphanumeric-on-os-x-w-appl http://blog.erikandcolleen.com/quick-easy-random-alphanumeric-on-os-x-w-appl

Often I find myself in situations where a little random string would be very handy, be it a password, a unique identifier, or some sort of throwaway data. The String Generator at random.org is great (and supposedly very random, so a must wherever true randomness is required), but I was looking for something quicker.

In a unixy environment, the following works:

$ head /dev/random | md5
96cfcc873597b02dfa97d3fc0a2fd9a0

While this does work in OS X, it would be nice to run it in a way that would work with my preferred app launcher, ideally without context switching away from whatever I was working on (i.e., not having to bring up Terminal).

The following is one line of AppleScript that leverages the same technique as above, but puts the resulting data into the system clipboard:

1
set the clipboard to (do shell script "head /dev/random | md5 | awk '{printf \"%s\", $1}'")

After generating a .app from the ActionScript, one simply runs the app and pastes the result as desired.

The generic .app icon is quite bland, so a tiny bit of Context Free Art generates an icon:

1
2
3
4
5
6
7
8
startshape S

background {a -1}

rule S {
CIRCLE {a -0.7}
S {s 0.99 x 0.15 y 0.15 r 4.5}
}

Which looks like:

Random MD5.app Icon

Put it all together and we have a simple Random MD5.app:

Download Random MD5.app

Permalink

]]>
http://files.posterous.com/user_profile_pics/1326808/Erik_Profile.png http://posterous.com/users/hcH2JKRhUmEqK Erik Beeson erikbeeson Erik Beeson