• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile this? ( Classpath problem)

 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am reading Thinking in JAVA and i am trying to compile the following code. It is giving me error on import statement.
Program
==============



==================
Compilation Error

My Classpath is as follows


===========
Please help me in compiling and understanding this program. I am sure that, i am missing something in classpath.
Thanks in advance,
Mubeen Shaik.
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember correctly the source code to the Eckels book is delivered uncompiled. There is a supplied build.xml file which compiles everything as long as ANT is installed.
regards
Nigel
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath is the path a class may be found.
you class com.bruteforce.sitest isn't found in:
C:\com\bruteforce\sitest
but in
C:\
and com\bruteforce\sitest belongs to that, what is found in C:\
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nigel,
I have compiled all the programs and created the classes. Still I am getting the same error.Any Help on this?.
Thanks,
Mubeen.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the output:
class file contains wrong class: com.bruceeckel.simpletest.Test
Please remove or make sure it appears in the correct subdirectory of the classpath
If the classname is Test and the package-declaration is: com.bruceeckel.simpletest.Test you have to put it into a directory x, such that:
x/com/bruceeckel/simpletest/Test.class
is it's location (revert the slashes in mind).
And x has to be in the classpath. (i.e: x=C:\)
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stefan,
Thanks for that. It worked and i have compiled the program. Now in my classpath i have "C:\".
Could you please explain me why it didn't work with this class path
C:\com\bruceeckle\simpletest.
Thanks in advance,
Mubeen Shaik.
 
Wai Hung
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the directory in classpath is the starting point.If you are importing com.bruceeckle.simpletest.*,
and your classpath have c:\
it will expect the class is in C:\com\bruceeckle\simpletest
but if your classpath is C:\com\bruceeckle\simpletest
then it will expect the class is in C:\com\bruceeckle\simpletest\com\bruceeckle\simpletest.
 
Mubeen Shaik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Thanks for that detailed explanation.This forum helps alot.
Thanks,
Mubeen Shaik.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic