Windows, Java and Cygwin: a Wrapper Script to Fix File Paths
So, at work I sometimes have to run Java code on both AIX and on Windows. If I want to test things, I have found it beneficial to run the entire thing under Cygwin. Unfortunately because of the difference in how paths are handled, stuff usually doesn't work right. So I created the script below. It doesn't work on everything, in particular it doesn't work for referencing your Log4J config from the command line. But, it works for my purposes.
In short, name this java.bat, put it first on your path under Cygwin, and it will fix MOST filenames so that they properly run.
If there is a better way to do this, let me know.
#!/bin/ksh
#fix java programs to run correctly with cygwin
export CLASSPATH="$(cygpath -wp "$CLASSPATH")"
x=0
lastvar=
for p in "$@"
do
#get path of the parameter if it has one
ppath="$(dirname "$p")" > /dev/null 2>&1
#exclude current dir
if [[ "$ppath" = "." ]]; then ppath=""; fi
#exclude if its not a directory already
if ! test -d "$ppath"; then ppath=""; fi
if [[ "$lastvar" = "-cp" ]]
then
parms[x]="$(cygpath -wp "$p")"
elif [[ "$lastvar" = "-classpath" ]]
then
parms[x]="$(cygpath -wp "$p")"
elif test -e "$p"
then
parms[x]="$(cygpath -wp "$p")"
elif [[ "$ppath" != "" ]]
then
parms[x]="$(cygpath -wp "$p")"
else
parms[x]="$p"
fi
lastvar="$p"
x=$(( $x + 1 ))
done
"$JAVA_HOME/bin/java" "${parms[@]}"
If there is a better way to do this, let me know.
Labels: Java, programming, shell scripting, UNIX

0 Comments:
Post a Comment
Nothing bad will happen to your information, I promise.
Subscribe to Post Comments [Atom]
<< Home