By Mitch Stuart
Copyright © 2005 FullSpan Software - Usage subject to license
Software Version: 1.0 - Document Version: $Revision: 1.1 $, $Date: 2005/12/26 06:03:42 $
whichcommand finds executable files by searching the
PATH, JWhich finds Java classes by searching the
Typical uses for JWhich are:
.tar.gzfile) into a directory of your choice. For the remainder of this document, we'll refer to this installation directory as
Before running JWhich, ensure that
JWHICH_DIR/build/lib/jwhich.jar is on the CLASSPATH.
To run JWhich, use this command line syntax (shown on multiple lines for clarity):
JWhich can search for 1, 2, or more resources in a single run - just specify all the class or other resource names on the command line.
java com.fullspan.jwhich.JWhich classOrResourceName1 classOrResourceName2 . . .
For example (command and output shown on multiple lines for clarity):
Important: The JWhich program (class com.fullspan.jwhich.JWhich) is packaged into a JAR file for convenience. However, the Main-Class attribute has not been set for the JAR file, so you will not be able to use the -jar switch to run JWhich like this:
java com.fullspan.jwhich.JWhich javax/servlet/http/HttpServletRequest.class java/lang/String.class javax/servlet/http/HttpServletRequest.class: jar:file:/home/mitch/prod/ jakarta-tomcat-4.1.30/common/lib/servlet.jar!/javax/servlet/http/ HttpServletRequest.class java/lang/String.class: jar:file:/usr/java/jdk1.5.0_06/ jre/lib/rt.jar!/java/lang/String.class
The reason is, as described in the java command documentation, with the -jar switch "the JAR file is the source of all user classes, and other user class path settings are ignored". Since the whole point of JWhich is to search the CLASSPATH, it wouldn't make any sense to enable the use of the -jar switch.
java -jar JWHICH_DIR/build/lib/jwhich.jarclassName
JWhich includes a shell script to help with the task of adding a directory of .jar and/or .zip files to the CLASSPATH: listJarsForClasspath.sh (you can view the script here). This is a bash script that can be run under Linux, or under the Cygwin shell in Windows (or wherever else a bash shell is available).
Run listJarsForClasspath.shwith no parameters to view the help message:
Usage (to display jar files): listJarsForClasspath.sh directory1 directory2 ... Usage (to add jar files to CLASSPATH): CLASSPATH=$CLASSPATH:$(listJarsForClasspath.sh directory1 directory2 ...) For each directory on the command line, this script lists all of the .jar and .zip files in that directory. The file names are separated by the path separator character (: or ; depending on platform).
A full discussion of ClassLoader issues is beyond the scope of this document. You can find more information through web searching, or by consutling a resource such as Stuart Halloway's Component Development for the Java Platform.
ant. This will use the
build.xmlbuild file in that directory.
To build JWhich using Eclipse, import the top-level JWhich directory as an Eclipse project.