Monday, November 17, 2008

jarfinder.com

Kudos to Frank Kelly for alerting the world -- via his blog -- to the existence of jarfinder.com. This is an online tool that helps people track down class path issues by reporting what JARs a particular class belongs to. It also helps you find the download pages for JARs you don't have. Over the years I have used a couple of different sites to do the same thing but for different reasons, those sites have fallen by the wayside. First, there was jarhoo.com, which has since decided to commercialize the venture and not offer free searches anymore. Then there was whatjar.net, which seems to have simply disappeared. In the intervening years I had simply used a shell script to search through JARs on my filesystem but am glad to see an easy-to-use online tool show up to complement this approach.

Monday, September 15, 2008

JUnit and the Working Directory

This is a quick post for my own notes more than anything. Oftentimes, your JUnit tests need to load up some stuff from files. Most of the time, you'll want to use getClass().getResourceAsStream() to do this. If that's not possible for some reason or another, and you need to use a relative path name to some resource for your JUnit test, and you're using an IDE to kick off your tests, what should that path be relative to? Here's a quick JUnit test that gave me that answer:

import junit.framework.TestCase;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class WorkingDirectoryTest extends TestCase {
public void testWorkingDirectory() throws Exception {
Process process = Runtime.getRuntime().exec("pwd");
InputStream stream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String result = reader.readLine();
System.out.println(result);
}
}

Friday, August 08, 2008

Installing Tomcat on OS X (The Hard Way)

Last week I set about installing Tomcat on an OS X client machine. Being a UNIX based OS, I figured I would put my sys admin hat on and install Apache's servlet container in a manner befitting of a multi-user UNIX environment. Looking at the OS X directory structure, I didn't see an obvious place for local application installations besides /usr/local. (I've seen various conventions used on Solaris based systems over the years -- /opt, /appl. /app -- and none were present.) I saw references to a few programs creating a /sw directory for installations but that just didn't gel with me. So after deciding on /usr/local for the installation location, I went ahead and laid Tomcat down in there.

The next step is to create a user account and group for this application. Running 'which adduser' revealed no such command in OS X. A Google search confirmed this. Apparently I needed to use a utility called 'dscl' for all user and group management (dscl also replaces the addgroup command). The following shows the commands run to create a user and group to own the application files and directories. Note that you can use whichever UID and GIDs you want, I just went with 701. Note also that most UIDs under 100 are pretty much taken up by OS services, so you'd want to go higher than that.

sudo /usr/bin/dscl . -create /Users/apache
sudo /usr/bin/dscl . -create /Users/apache uid 701
sudo /usr/bin/dscl . -create /Users/apache home /var/empty
sudo /usr/bin/dscl . -create /Users/apache shell /usr/bin/false
sudo /usr/bin/dscl . -passwd /Users/apache \*
sudo /usr/bin/dscl . -create /Groups/apache
sudo /usr/bin/dscl . -create /Groups/apache gid 701
sudo /usr/bin/dscl . -create /Users/apache gid 701
sudo /usr/bin/dscl . -append /Groups/apache GroupMembership apache
sudo chown -R apache:apache /usr/local/apache-tomcat-5.5.26/

Then of course you'll probably want to add your own user id to the apache group and setup permissions appropriately so you can work with the installation. The easy way to install Tomcat and get it up and running was obviously just to install it my home directory. No-one learns anything that way though.

Useful Links:
[discussions.apple.com]
[developer.apple.com]
[jlbtc.eduunix.cn]

Update: I just came across this article by Malis Photo that goes further than my post in setting up the Tomcat Native Library extensions and other bibs and bobs which are important for production deployments. Interestingly, they've chosen to use /Library/Tomcat as the installation location.