Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java path problems on Cygwin

Tags:

java

cygwin

I'm trying to compile a Java project under Cygwin using a native Win32 Java.

The Java binaries are correctly found under /cygdrive/c/jdk/bin on my machine.

The following command works fine:

javac -d . ./gnu/kawa/util/PreProcess.java

The PreProcess.class file is generated in ./gnu/kawa/util/. Trying to invoke Java on this fails however:

CLASSPATH=.:$CLASSPATH java gnu.kawa.util.PreProcess \
   %java6 +use:com.sun.net.httpserver +enable:XML \
   `sed -e 's|\([^ ]*\)|./\1|' < ./patch-source-list`
Error: Could not find or load main class gnu.kawa.util.PreProcess
...

This command was invoked by make, that's where the $CLASSPATH variable is set dynamically. patch-source-list is just a list of class names. The : in the classpath looks suspicious, but I'm not sure how to test ; while not annoying sh.

My only other suspicion is that the native Java is trying gnu\kawa\util\PreProcess, but I think cygwin can transparently handle that.

Any ideas? Thanks for your time.

like image 265
Charles Avatar asked Mar 16 '26 08:03

Charles


2 Answers

Another option would be to build your path using the ':' and then fix the results using cygpath. This is probably overkill in your specific situation, but in a general case where you may have references to multiple directories, some of which may be referenced as absolute rather than relative paths, or if you are working with cygwin symlinks, it is much more useful.

$ ln -s /cygdrive/c/development/libraries/ ../libs
$ cygpath -pw /cygdrive/c/development/:.:../libs
C:\development\;.;C:\development\libraries\

so then you'd build your CLASSPATH variable as before, and in the final stage run

CLASSPATH="`cygpath -pw "$CLASSPATH"`" java (whatever)
like image 96
user3073119 Avatar answered Mar 18 '26 22:03

user3073119


Remember, the JVM has no idea that you are using the cygwin bash shell.

Two things:

  1. for the classpath locations, use the windows path names. Thus, no "/cygdrive/c/somepath", but "c:\somepath\" ("/" and "\" can be used interchangeably however)
  2. use ';' instead of ':' in the classpath list

This should work:

export CLASSPATH="./gnu/kawa/util/PreProcess.class"
CLASSPATH=".;$CLASSPATH" java gnu.kawa.util.PreProcess
like image 25
dstibbe Avatar answered Mar 18 '26 21:03

dstibbe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!