Results 1 to 6 of 6
  1. #1
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default Error compiling java subclass from command prompt

    Good Afternoon,

    I have been trying for about an hour to compile two java subclass for the Command Prompt. All of the classes are in the same directory.

    The classes are as follows:

    Java Code:
    Book.java - the superclass
    
    ChildrenBook.java - a subclass of Book
    
    TechnicalBook.java - a subclass of Book.

    All of the files are saved under this folder:


    Java Code:
    C:\tomcat\webapps\begjsp-ch07\WEB-INF\classes\com\wrox\library
    This is the command I am running at the command prompt:

    Java Code:
    javac com\wrox\library\Book.java
    javac com\wrox\library\TechnicalBook.java
    javac com\wrox\library\ChildrenBook.java

    The Book.java class compiles, but when I run the above commands, I get this error message:

    Java Code:
    cannot find symbol
    symbol: class Book

    I have attached my CLASSPATH, the error message, and the all of the java classes.

    Please directly me on exactly what is causing this problem. I have a feeling it has to do with my CLASSPATH not being setup properly. I am using Tomcat 6 with jdk 1.6.0_21


    Thanks in advance for all of your help.
    Attached Thumbnails Attached Thumbnails Error compiling java subclass from command prompt-classpath.jpg  
    Attached Files Attached Files

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    First, when you run the command in your command promt you are in C:\tomcat\webapps\begjsp-ch07\WEB-INF\classes, right?

    Set the classpath to the current directory ('.')! (or you can use the -classpath/-cp option in javac)

    try
    Java Code:
    javac -cp . com\wrox\library\TechnicalBook.java
    javac -cp . com\wrox\library\ChildrenBook.java
    (-cp = -classpath)

    javac com\wrox\library\Book.java is not necessary

    or you can use the wildcard (you do not have to set the classpath AFAIR)
    Java Code:
    javac com\wrox\library\*

  3. #3
    makpandian's Avatar
    makpandian is online now Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    441
    Rep Power
    6

    Default

    I am sure that it because of classpath.

    You better go through

    PATH and CLASSPATH (The Java™ Tutorials > Essential Classes > The Platform Environment)
    Mak
    (Living @ Virtual World)

  4. #4
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Thank for the reply. I want to make sure that I am understanding you right.

    First you want me the change the set the CLASSPATH to include the ".". (Please see jpg attachement).

    Secondly, yes I did enter the correct path. (Please see my a screen shot of my command from yesterday).

    I will take your suggestions you provide and post my results.

    Thank for the fast and concise suggestions you provided. I really appreciated.
    Attached Thumbnails Attached Thumbnails Error compiling java subclass from command prompt-1-error_-cannot-find-symbol-class-book.jpg  
    Last edited by littleone; 10-26-2010 at 05:58 PM.

  5. #5
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Sure enough that was the case.

    All I needed to do was to add the "." to the beginning of the CLASSPATH and rerun the javac command along with the path and the two files compiled.

    Thanks for the help. I will be back pretty soon bugging you all for more help because I am having problems getting my servlets to work.

  6. #6
    pranabpradhan is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default

    1. run the command FROM command promt going to --> C:\tomcat\webapps\begjsp-ch07\WEB-INF\classes location.

    2. Set the classpath to the current directory ('.').

    3.
    execute the following

    javac -cp . com\wrox\library\TechnicalBook.java
    javac -cp . com\wrox\library\ChildrenBook.java

    (-cp = -classpath)

    4. javac com\wrox\library\Book.java is not required
    Last edited by pranabpradhan; 10-26-2010 at 03:48 PM.

Similar Threads

  1. error in the Command Prompt when running a bat file
    By bluesagemedia in forum New To Java
    Replies: 1
    Last Post: 10-03-2010, 01:05 AM
  2. Compiling/Running in Command Prompt
    By coke_in_a_can in forum New To Java
    Replies: 12
    Last Post: 05-31-2010, 09:05 AM
  3. How to return command prompt error message
    By raxwer in forum Advanced Java
    Replies: 3
    Last Post: 05-26-2010, 05:15 PM
  4. running command prompt using java
    By xclaim in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 03:46 AM
  5. Command Prompt Java
    By kelvinsmj in forum New To Java
    Replies: 8
    Last Post: 11-27-2009, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •