• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with the java command and -classpath concerning the current (.) directory

 
Ulrich Vormbrock
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

when I try to run a file from the console (vi-editor) typing
java MyClass,
it works fine.

Instead, when I add a "-classpath" to the java command, I always get a NoClassDefFoundError, although I include the currrent directory in the classpath:
java -classpath .:subdir MyClass

I'm wondering why, because the current directory is always present, so why does the JVM not find my class file?
Same problem with the windows console, I've even tried out ";" instead of ":" as delimiter.

Any ideas?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulrich,
Could there be something in that classpath that is breaking it?

Does this work? java -classpath . MyClass

If so, try adding one directory at a time to the classpath.

 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Beginning Java.
 
Ulrich Vormbrock
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

thank you for your reply!
Yes, indeed:

java -classpath . MyClass

works out fine, but as I add only one valid subdirectory (-classpath .:subdir), I always get the same error message!
I'm not sure if this problem is related to the underlying OS.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Urlich,

what is the name of 'notfound' class displayed in the stacktrace, is it MyClass or maybe some other class ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show the complete file hierarchy, indicate from where you are running the command, and which OS you're actually using.
 
Ulrich Vormbrock
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

attached please find a screenshot of my different commands (java versus java -xlasspath) - so you can see what the exact error message is.
I run the java command from the dev directory, and x is a valid subdirectory of dev.
My OS is Windows Vista, and as I've written, I use Cygwin in order to emulate Unix.

Same problem when I use the Windows console (instead of Cygwin).
classpath.jpg
vi editor: different java commands
[Thumbnail for classpath.jpg]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh; please don't use screenshots to capture textual information. Just text is fine.
as I've written, I use Cygwin in order to emulate Unix.

First time Cygwin's been mentioned in the thread, and it matters.

Are you using the Windows version of Java, or a Cygwin version? If Windows, in Cygwin, you still need to use a semi-colon as the path separator. And, because it's Unix-like, you need to escape the semicolon in the path.
 
Ulrich Vormbrock
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

sorry for that and thank you very much for your hint concerning escaping the semicolon.

Now, I've typed
$ java -classpath .\;x SerializeTest

and it works out fine.
Besides, I use the Windows version of java ...

Cheers!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear you got it worked out :) Yeah, that's kind of a pain, but for me the Windows version of Java is the most reliable and has the least bugs--I do the same thing sometimes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic