The perils of cygwin and classpaths
A largely unenjoyable couple of hours was spent tracking down a nasty little issue surrounding classpaths in cygwin. First a little background. On Windows, if you want to specify a classpath, java expects it to be a series of semi-colon separated paths, like so:
set CLASSPATH=c:\lib\some.jar;c:\classes\;.;
On Unix, java expects a colon separated list:
export CLASSPATH=/usr/lib/some.jar:/home/export/myarea/;.
I’m playing around with using a shell script to run my app on windows, however I’m using cygwin as I hate writing bat files. This is a bit of a problem however – cygwin expects Unix format paths, but we’re still running a Windows version of java. Once I’d worked out that this is what was causing the strange ClassNotFoundExceptions, a quick google turned up cygpath, which can translate from Windows to UNIX paths (and vice versa). So, when invoking java in my shell script I just changed:
java -classpath $MYCLASSPATH org.package.MyClass
to:
java -classpath `cygpath --path --windows $MYCLASSPATH` org.package.MyClass
Next up, I can change my script to work on Unix by conditionally invoking cygpath only if I’m running in a cygwin bash shell.
This entry was posted on Monday, August 16th, 2004 at 5:39 pm and is filed under Java. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
Have your say
Fields in bold are required. Email addresses are never published or distributed.
Some HTML code is allowed:
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.
Line breaks and paragraphs are automatically converted.
Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.