Reputation: 618
I have a simple Java program that prints out my classpath. Folder structure is as follows:
[~/tmp/bin]# ls
launcher/ PrintClasspath.class*
And a copy of the same class one more level down in.
[~/tmp/bin/launcher]# ls
PrintClasspath.class*
When I jump up to my ~/tmp
directory and run PrintClasspath
in my ~/tmp/bin
directory, I can run the program just fine, stating ./bin
as the classpath.
[~/tmp]# java -cp "./bin" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/
Or I can run the same file I nested in the ~/tmp/bin/launcher
directory if I edit the classpath as follows:
[~/tmp]# java -cp "./bin/launcher" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/launcher/
But when I try to sit in my ~/tmp
directory, and try to run my class in the ~/tmp/bin/launcher
directory with ./bin
as my classpath and qualify where the class is located via the following:
[~/tmp]# java -cp "./bin" launcher.PrintClasspath
Error: Could not find or load main class launcher.PrintClasspath
It FAILS. I've run the same test on my Linux box, and qualifying where the class is located in a sub-directory after giving a classpath multiple directories up works fine.
I originally assumed this was a Windows/Cygwin nuance, but I tried the same exercise in Windows command prompt and same result. What am I missing here.do I just have to run my Windows Java programs with a fully qualified classpath?
Upvotes: 1
Views: 894
Reputation: 181
This is not an answer. I can not comment yet. I wanted to note that this helped me with a problem where I was running javac -cp foo:bar/none which worked on Mac OS. In cygwin on windows it did not work, giving multiple errors about not finding a project xxxx in bar/none. xxxx was already compiled in bar/none. Using cygpath -wp foo:bar/none solved my problem. Example
javac -cp `cygpath -wp foo:bar/none` -d out/whatever/there src/*.java
Upvotes: -1
Reputation: 618
Solved: When setting the classpath in Cygwin using the Windows version of Java, you have to use the cygpath
utility with options -wp
to convert the unix style paths to Windows paths.
[~/tmp]# java -cp `cygpath -wp ./bin` launcher.PrintClasspath
/C:/Cygwin/home/user/tmp/bin/
(via this)
Upvotes: 2