example

Ant WAR task - A sample Ant build script that builds a WAR file

You'll probably have to know a little bit about Java, Ant, and build files for this sample build.xml file to be any use to you, but if you're looking for a sample Ant build script that can be used to create a war file, or one that simple uses a war task, this example might work for you.

I'm not going to provide any explanation of any of this right now, but if I have time in the future I'll come back here and add a few comments about how this build script works.

Database-driven version of states dropdown data

Some time ago I created a brief blog entry that shows an HTML select/option block for displaying all the states in the United States in a dropdown list (combo box). After a few requests I'm now providing that same information here in a database table format.

How to set the default input focus on a field in an HTML web form

When I create a web-based user interface I tend to be a fanatic about making sure that the first input field on a form gets input focus when the form is first displayed. It always drives me crazy when I go to a web form that requires text input, but the developer of the page hasn't taken the time to put the default focus in the first field of the form.

So ... after looking around at some HTML/JSF/Struts/JSP code I've written over the last few years, the following JSF example shows the most concise way I know of setting default input focus on an HTML form field:

An Effective Java note on reusing existing Exception classes

I just read a short chapter in the book Effective Java, and realized I was doing something pretty dumb in my own code by always creating my own custom exceptions instead of using other exceptions already intended to be reused in the Java API.

Specifically:

Sample Cobertura ant build script

Summary: A Sample Cobertura Ant build script.

I still haven't gotten around to writing a Cobertura code-coverage tutorial, but in lieu of that, I thought I'd include an ant build script here that does a lot of powerful things, including a task that generates Cobertura code-coverage reports.

Java error message: Cannot make a static reference to the non-static field or method

If you've ever seen a Java compiler error message like "Cannot make a static reference to the non-static method doFoo" or "Cannot make a static reference to the non-static field foo", here's a quick explanation of these messages.

What is a Java NoSuchMethodException?

Java exception FAQ: What is a Java NoSuchMethodException?

Answer: Using Java, you can get a NoSuchMethodException when you're using reflection and try to dynamically use a method on a class, and the method does not actually exist. The following example Java class shows how this NoSuchMethodException can be generated:

What is a Java ClassNotFoundException?

Java Exception FAQ: What is a ClassNotFoundException?

Answer: A ClassNotFoundException can happen when you use Java's Reflection capability to dynamically create a class. Here's some example code where I intentionally throw a ClassNotFoundException by trying to create and use a class ("FooClass") that I know doesn't exist:

Java alphanumeric patterns: How to remove non-alphanumeric characters from a Java String

Java String "alphanumeric" tip - How to remove non-alphanumeric characters from a Java String.

AppleScript tip: script a program that isn't scriptable

If you ever want/need to use AppleScript to drive another program that doesn't have AppleScript support, there are a few things you can do. Here's a snippet of code where I'm opening new tabs in Safari, and typing text into the location field:

Syndicate content