Friday, November 16, 2012

Use cygpath with -p option for your Java CLASSPATH conversion

I just noticed that Cygwin's cygpath command supports -p option. This is a real gem when writing Java wrapper script that needs to covert CLASSPATH values. A simple script can demonstrate the purpose.

#!/usr/bin/env bash
# Author: Zemian Deng, Date: 2012-11-16_06:30:00
# - A simple Java wrapper script for Cygwin and Unix/Linux shell. We assume 
# this script is located in a subdiretory inside the application home directory.
# Example:
#   app/bin/
#   app/config/
#   app/lib/log4j.jar
# Usage:
#   bash> app.Hello
DIR=$(cd "$(dirname $0)/.." && pwd)
if [[ "$OS" == Windows* ]]; then
 CP=$(cygpath -mp $CP)
java -cp "$CP" "$@"

No comments:

Post a Comment