Shell Scripts, Command Lines, and Classpathsby Daniel H. Steinberg
If you've come to Java programming on a Mac from a Windows environment, you've probably noticed that things are a bit different on the Mac.
This month we look at issues involving classpaths and running applications from the command line and through shell scripts. This is not the way you'll usually distribute your applications to end users. You will, however, find that applications aimed at developers will require that you run them from the command line or through shell scripts. On a Windows box, you can double-click on a
.bat file. With Mac OS X, you'll need to package them up using these basic techniques.
Java and XML on the Mac
At this year's JavaOne conference, Sun announced that it would provide a collection of its Java APIs for XML called the JAX Pack. Much of the technology would find its way into the releases of J2SE, but as J2SE is now released every year and a half, the JAX Pack is updated quarterly. If you've poked around the J2SE 1.4 beta, you know that it includes JAXP (the Java APIs for XML parsing). Mac OS X developers don't have a version of the 1.4 beta to play with on our boxes, but this shouldn't keep us from joining in the fun. Incidentally, a Java-friendly, open-source alternative to JAXP is JDOM. This article will also take a quick look at Xeena, the XML editor from alphaWorks.
Those of you who have tried Java programming in the Mac environment, what do you have to say?
In this month's article, you'll download and install JAXP and take it for a test drive. This involves creating shell scripts or modifying your
.login files. You should be warned that I don't know anything about Unix that I haven't discovered through fooling around with Mac OS X. If there are nicer ways to accomplish these tasks you should post feedback to this article and email James Duncan Davidson demanding that someone take away my key to the O'Reilly writers' lounge (like there is one). This material is intended to help those of us that have been used to setting classpaths on a Windows box better understand the way Unix-heads think.
Next month, we'll return to the comfort of programming in Java and begin to develop an application that works with XML and shows off some of the Mac's special features.
Head to Sun's XML site. Follow the JAXP link and choose to download the JAXP reference implementation from the list at the right of the page. You will have to log in as a JDC member (if you're not a member, you can join for free). You can follow way more steps than you need to, or just navigate to http://java.sun.com/xml/download.html and download the final version of JAXP 1.1. Unzip the file into the
Applications directory of your home directory. In my case, that's in
/Users/dhs/Applications. You should replace
dhs with your user name. Finally, change the name of the directory from
jaxp so that these instructions will remain relevant for future releases.
Really the only thing left to do is to make sure your classpath is set correctly to find three
xalan.jar. The easiest way to do this on a Windows platform is to copy the three files into the
/lib/ext directory (or as they put it, your
\lib\ext directory) where your Java distribution is. You'll find this on your Mac in
/System/Library/Frameworks/JavaVM.framework/Home. Go ahead and try to drag your
.jar files from the
jaxp folder into the
ext directory. You'll be warned that this can't be done because "ext can't be modified." Sigh.
After your initial frustration, you may realize that this is probably a good thing for now. You don't have to worry about automatic system updates hosing your customizations. Just keep your jar files where they are for now and add that location to the classpath. You have three basic choices: (1) type in all of the commands on the command line, (2) create a
.login file that is read when you open up the terminal window, or (3) create a shell script that includes this information when you run a particular application.
I'll treat the third option in getting the Xeena application to run. I'll have a couple of quick comments on the second option and a pointer to another Mac DevCenter article at the end of the next section. Let's start with a look at setting up your classpath from the command line. If you've used ProjectBuilder, these are the red commands that stream by when you choose to build and run your project.
Pages: 1, 2