Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on java classpath

 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code:



And this class: Development/Java/net/mindview/util/Print.class. CLASSPATH envvar has the value Development/Java.

With this setting I'm able to compile with success Print.java typing javac Print.java. I would expect to use the same syntax to run java, instead I have to type java -cp . evelopment/Java Print or I get is this error:

Exception in thread "main" java.lang.NoClassDefFoundError: Print

At this point, I'd like to know why in the latter case I have to specify a classpath (even if CLASSPATH variable already contains the right path), while javac doesn't require this?

Thanks
[ December 26, 2008: Message edited by: Paolo Dina ]
 
Paolo Dina
Ranch Hand
Posts: 63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this class: Development/Java/net/mindview/util/Print.class. CLASSPATH envvar has the value Development/Java.


Just found by myself, sorry... it was that CLASSPATH should include the current directory also!
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paolo Dina:


Just found by myself, sorry... it was that CLASSPATH should include the current directory also!


No need to be sorry; well done working it out, and thank you for posting the solution to help other readers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic