<< Meta-Meta-Meta | Home | Mono Beta 1 Here, 1.0 in June >>

JARPATH

The concept of the CLASSPATH has been with us since the beginning. The concept of the Jar file has also been with us for some time now, although I still remember the time when it was introduced in JDK 1.1.

I've always felt that there is something wrong with both concepts, but couldn't pin it down.

Today I had an A-ha moment: The way Java's going about putting classes into a CLASSPATH is just silly. We should be using something like a JARPATH, not CLASSPATH.

The Java class file is no longer the unit of distribution of modern Java systems. We deliver our systems as a set of Jar files. Yet we insist on maintaining a CLASSPATH.

This is the wrong level of granularity.

We sort of already have a solution for this problem in the context of web apps with its WEB-INF/lib directory. We also can use the JRE extension mechanism whereby you can put a jar file into the $JRE_HOME/lib/ext.

But can't we persuade Sun to introduce a JARPATH environment variable? So that instead of doing:

export CLASSPATH=$CLASSPATH:/opt/jboss-3.2.3/client/concurrent.jar:\
/opt/jboss-3.2.3/client/getopt.jar:\
/opt/jboss-3.2.3/client/gnu-regexp.jar:\
/opt/jboss-3.2.3/client/jacorb.jar:\
/opt/jboss-3.2.3/client/jbossall-client.jar:\
/opt/jboss-3.2.3/client/jboss-client.jar:\
/opt/jboss-3.2.3/client/jboss-common-client.jar:\
/opt/jboss-3.2.3/client/jbosscx-client.jar:\
/opt/jboss-3.2.3/client/jbossha-client.jar:\
/opt/jboss-3.2.3/client/jboss-iiop-client.jar:\
/opt/jboss-3.2.3/client/jboss-j2ee.jar:\
/opt/jboss-3.2.3/client/jboss-jaas.jar:\
/opt/jboss-3.2.3/client/jbossjmx-ant.jar:\
/opt/jboss-3.2.3/client/jboss-jsr77-client.jar:\
/opt/jboss-3.2.3/client/jbossmq-client.jar:\
/opt/jboss-3.2.3/client/jboss-net-client.jar:\
/opt/jboss-3.2.3/client/jbosssx-client.jar:\
/opt/jboss-3.2.3/client/jboss-system-client.jar:\
/opt/jboss-3.2.3/client/jboss-transaction-client.jar:\
/opt/jboss-3.2.3/client/jcert.jar:\
/opt/jboss-3.2.3/client/jmx-connector-client-factory.jar:\
/opt/jboss-3.2.3/client/jmx-ejb-connector-client.jar:\
/opt/jboss-3.2.3/client/jmx-invoker-adaptor-client.jar:\
/opt/jboss-3.2.3/client/jmx-rmi-connector-client.jar:\
/opt/jboss-3.2.3/client/jnet.jar:\
/opt/jboss-3.2.3/client/jnp-client.jar:\
/opt/jboss-3.2.3/client/jsse.jar:\
/opt/jboss-3.2.3/client/log4j.jar:\
/opt/jboss-3.2.3/client/xdoclet-module-jboss-net.jar

I can simply do:

export JARPATH=$JARPATH:/opt/jboss-3.2.3/client


Re: JARPATH

Java : UNIX :: JARPATH : LD_LIBRARY_PATH

Re: JARPATH

Well, there's the endorsed libraries mechanism...

Re: JARPATH

JARPATH=`ls ./lib/* | tr '\n' :`

Re: JARPATH

I've been using something like that. Here's my /etc/profile.d/jboss.sh file that builds up the CLASSPATH:

# JBoss initialization script (sh)
#
JBOSS_HOME=/opt/jboss-3.2.3
JBOSS_CLASSPATH=`echo $JBOSS_HOME/client/*.jar $JBOSS_HOME/server/default/lib/javax.servlet.jar* $JBOSS_HOME/server/default/lib/mail.jar* | tr ' ' :`
if ! echo $CLASSPATH | grep -q "$JBOSS_CLASSPATH" ; then
        if [ -z $CLASSPATH ]; then
                CLASSPATH=$JBOSS_CLASSPATH
        else
                CLASSPATH="$CLASSPATH:$JBOSS_CLASSPATH"
        fi
fi
unset JBOSS_CLASSPATH
export CLASSPATH JBOSS_HOME

Re: JARPATH

The endorsed libraries directory is a bad idea. Until version support is added (like .Net's GAC) the endorsed directory should be avoided. If you're writing a completely self-contained application (a swing app for example), you could use your own class loader. It could easily search a JARPATH for jar files and include them in the search.

Re: JARPATH

Classworlds?

Not exactly same idea, but some other projects such as classworlds present approaches to the classpath issues and form a 'superset' to the jarpath idea.

Of course, a standard jarpath would be nice, reduces the external script complexities or noise.

Re: JARPATH

JARPATH="/usr/pkg/share/classpath:/usr/pkg/lib/java:$JARPATH" JARPATH=`echo $JARPATH | awk '{ gsub(/:/," "); print $0}'` for A in $JARPATH ; do for B in `ls $A/*.jar 2> /dev/null` ; do CLASSPATH=$B:$CLASSPATH done done echo $CLASSPATH

Add a comment Send a TrackBack