Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compling files using classpath  option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compling files using classpath  option" Watch "compling files using classpath  option" New topic

compling files using classpath option

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

KB book Ch-Development SELF TEST

9. Given the following directory structure:
|- FindBaz.class
|- test-|
|- Baz.class
|- myApp-|
|- Baz.class

  And given the contents of the related .java files:

  In the test directory:
  In the myApp directory:

-------------------------------------------------------------------------- complied fine and is store in the test directory.
i am trying to compile the file using this command at cmd:


but i get the following error cannot find symbol
symbol : class Baz
location: class FindBaz
public static void main(String[] args) { new Baz(); }
1 error

how to remove this error ?
then ,i cut the file from x to test directory where the file is placed along with it's Baz.class file

C:\PROGRA~1\Java\JDK16~1.0_1\bin\x>cd test

C:\PROGRA~1\Java\JDK16~1.0_1\bin\x\test>javac cannot find symbol
symbol : class Baz
location: class FindBaz
public static void main(String[] args) { new Baz(); }
1 error

what shall i do ?

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774

As per my understanding, you need to specify the correct path for Baz class when you try to compile
Even putting the class into same directory will not solve the problem. Provide the correct path till Baz using -cp flag.
It will solve your problem.

Hope this helps,

My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

-cp option may not run on all the machines
so I recommend you to use the -classpath option

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
I agree. Here's the link:
subject: compling files using classpath option
Similar Threads
Compiling problem for Scjp
K&B Chapter 10 Self Help Question 9
question about classpath
CLasspath Problem
java command question