Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 53529 invoked from network); 8 Jul 2000 02:48:18 -0000 Received: from new-smtp1.ihug.com.au (root@203.109.250.27) by locus.apache.org with SMTP; 8 Jul 2000 02:48:18 -0000 Received: from socialchange.net.au (p59-max56.syd.ihug.com.au [206.18.106.187]) by new-smtp1.ihug.com.au (8.9.3/8.9.3) with ESMTP id MAA01159; Sat, 8 Jul 2000 12:48:08 +1000 Sender: jeff@new-smtp1.ihug.com.au Message-ID: <3966950F.C59FFDB2@socialchange.net.au> Date: Sat, 08 Jul 2000 12:42:23 +1000 From: Jeff Turner Reply-To: jeff@socialchange.net.au Organization: Social Change Online X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.10 i586) X-Accept-Language: en MIME-Version: 1.0 To: general@jakarta.apache.org, ant-dev@jakarta.apache.org Subject: Dev environment for multiple Ant-based projects Content-Type: multipart/mixed; boundary="------------C2521FCD89FD6A2E7E8408A1" This is a multi-part message in MIME format. --------------C2521FCD89FD6A2E7E8408A1 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi all, I was wondering, how do most people manage their CLASSPATHs and shell environment in general when working with multiple Ant-based projects? I've assumed *nix here, but the question applies to all platforms. In a standard Ant-based project, you've got: - build.(sh|bat) in the project root - the code you're working on in src/* - the jar files necessary to build in lib/* and perhaps src/classes/WEB-INF/lib/* Now to do the usual code-compile-debug cycle, it would seem that you either have to: - keep jumping between your source directory and project root, eg $ vi Foo.java $ cd ../../../../../ $ ./build.sh $ cd src/WEB-INF/classes/bar/baz - or preset your CLASSPATH to include the source root, and stuff in /lib and WEB-INF/classes/lib, and compile in the source directory. I suspect most people choose the second option. This breaks the clean notion of everything going through Ant, and puts the burden of CLASSPATH maintenance on developers instead of the build system. Developers can no longer jump between projects without first fixing their CLASSPATH. One could of course have a universal CLASSPATH with all possibly useful jars, but that's a headache to maintain, especially when different projects need different versions of the same jar. Anyway, a solution I came up with was to have a .projrc file in each project root, and to invoke a new shell which uses .projrc. The new shell provides an environment where project-specific CLASSPATHs, aliases and whatnot can be set, and cleanly unset when the developer stops working, or switches to another project. Currently, the .projrc sets the CLASSPATH, sets $HOME to the project root, and creates an alias 'cdc' to the working code directory. Most of the work is done in a global /etc/projrc file. If anyone wants to play with it, the files are attached. --Jeff --------------C2521FCD89FD6A2E7E8408A1 Content-Type: text/plain; charset=us-ascii; name="projrc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="projrc" # Generic Java Project build environment # # This lives in /etc, and is called from project-specific .projrc files. # # Environment variables that can be preset: # $LONG_NAME The long form of the project name # $SHORT_NAME Short project name. This will appear in the prompt # $DESCRIPTION Short project description # $CODE The main working code directory. The 'cdc' alias will point to here # # Written under bash; possibly not portable across shells. Comments and improvements most welcome. # # Jeff Turner (jeff@socialchange.net.au) # $Header: /etc/RCS/projrc,v 1.3 2000/07/08 02:33:11 jeff Exp jeff $ # # Puts jars from directory $1 into CLASSPATH function loadjars() { echo "Loading jars from $1" if [ -d "${1}" ]; then for JAR in ${1}/*.jar ; do echo "Adding ${JAR}" export CLASSPATH=${CLASSPATH}:${1}${JAR} done else echo "${1} is not a directory." fi } # We want our old aliases still . ~/.bashrc echo -e "----------------------------------------------------------" echo -e "Proj name: ${LONG_NAME}" echo -e "Proj alias: ${SHORT_NAME}" echo "Proj description:" echo echo "${DESCRIPTION}" echo echo -e "----------------------------------------------------------" # Set the prompt to make it obvious that this is the project's build environment export PS1="[\u@\h \033[1;34m${SHORT_NAME}\033[0m \w]\$ " # Reset the CLASSPATH to common jars needed by all projects export CLASSPATH=${JAVA_HOME}/lib/tools.jar:${JAVA_HOME}/jre/lib/rt.jar # This resetting of $HOME might annoy some people. Specifically, my editor can't find it's config file in $HOME anymore. I find the ability to type 'cd' to jump to the project root outweighs the cost. export OLDHOME=${HOME} export HOME=`pwd` # Common locations for jars loadjars ~/lib loadjars ~/src/WEB-INF/lib echo if [ "${CODE}" = "" ]; then export CODE=src/WEB-INF/classes/ fi alias cdc="cd ${CODE}" --------------C2521FCD89FD6A2E7E8408A1 Content-Type: text/plain; charset=us-ascii; name=".projrc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename=".projrc" # This lives in your project root directory. # The variables are explained in /etc/projrc # # jeff@socialchange.net.au LONG_NAME="Project Foo" SHORT_NAME="proj-foo" CODE=src/WEB-INF/classes/net/socialchange/proj-foo DESCRIPTION="This project does absolutely nothing other than demonstrate the build environment script. Type 'cdc' to get to the code, 'cd' to get to the root. Notice how your CLASSPATH is specific to this project. Press ctrl-D to exit the project shell." . /etc/projrc --------------C2521FCD89FD6A2E7E8408A1 Content-Type: application/x-sh; name="proj.sh" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="proj.sh" #!/bin/sh # This should live with .projrc in your project root directory. bash -rcfile .projrc --------------C2521FCD89FD6A2E7E8408A1--