• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

-classpath question from a beginner

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

my name is Rory and I am brand new to java.
I have decided to do the SCJP 1.5 exam and I am thinking about doing the Cattle Drive to get some good background instead of studying solely for an exam pass.

I thought i understood the classpath option for sdk tools like java and javac but maybe not.

How can it be that if i type;
c:\>javac -classpath c:\javafiles\juggling Diabolo.java

I get;
error: cannot read: Diabolo.java
1 error

but if i type;
c:\>cd javafiles\juggling
c:\javafiles\juggling>javac Diabolo.java

It works!

I thought the classpath option would direct the compiler to the correct directory - what am I missing?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-classpath <path> Specify where to find user class files,
not java files.
It seems that you would use the -sourcepath <path> option with this statement.

using -classpath with javac would help if you had compilation of one class (maybe a subclass) dependent on a .class file in a different directory.

By the way, welcome to JavaRanch. It seems that path and classpath generate more confusion than most java issues, so don't hesitate to ask questions.
[ August 06, 2007: Message edited by: Marilyn de Queiroz ]
 
Rory Lynch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That explains a lot.

1. Why it was not working as I expected.
2. Why it worked for one of my .java files which depended on a user-defined class.
3. why I am a greenhorn.

Got a smile out of me!
And welcome, Rory!

(Sorry to edit your post, I meant to edit with quotes and goofed! )
[ August 06, 2007: Message edited by: Carol Murphy ]
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome, Rory!

Lots of helpful folks around here, so don't hesitate to ask your heart out
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to javaranch!

PLease check your java file.
the place where you are compiling your .java file that file not present in that folder.first go to the foder where you kept this file and then compile Diabolo.java
-classpath option we are using to specify where is our .classes are present
suppose if your Diabolo.java depends on some classes (external) then use -classpath and set classpath for that classes file
 
Rory Lynch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone!
 
reply
    Bookmark Topic Watch Topic
  • New Topic