Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Classpath override not working correctly in command prompt?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Classpath override not working correctly in command prompt?

    I am trying to run my program in command prompt using -classpath override. Take a look at what i tried here, and what resulted when I tried to give the classpath from a higher root directory. I am wondering why it can't find the file.

    C:\Program Files\Java\src\com\scjaexam>dir
     Volume in drive C is OS
     Volume Serial Number is 8873-03A4
     
     Directory of C:\Program Files\Java\src\com\scjaexam
     
    12/06/2011  01:38 PM    <DIR>          .
    12/06/2011  01:38 PM    <DIR>          ..
    12/06/2011  01:42 PM    <DIR>          ex2_1
    11/17/2011  12:49 PM    <DIR>          tutorial
                   0 File(s)              0 bytes
                   4 Dir(s)  112,734,724,096 bytes free
     
    C:\Program Files\Java\src\com\scjaexam>cd ex2_1
     
    C:\Program Files\Java\src\com\scjaexam\ex2_1>dir
     Volume in drive C is OS
     Volume Serial Number is 8873-03A4
     
     Directory of C:\Program Files\Java\src\com\scjaexam\ex2_1
     
    12/06/2011  01:42 PM    <DIR>          .
    12/06/2011  01:42 PM    <DIR>          ..
    12/09/2011  11:14 AM                82 iterator.java
                   1 File(s)             82 bytes
                   2 Dir(s)  112,734,724,096 bytes free
     
    C:\Program Files\Java\src\com\scjaexam\ex2_1>javac -cp iterator.java
    javac: no source files
    Usage: javac <options> <source files>
    use -help for a list of possible options
     
    C:\Program Files\Java\src\com\scjaexam\ex2_1>javac -cp . iterator.java
    iterator.java:1: ';' expected
    package com.scjaexam.ex2_1
                              ^
    1 error
     
    C:\Program Files\Java\src\com\scjaexam\ex2_1>javac iterator.java
    iterator.java:1: ';' expected
    package com.scjaexam.ex2_1
                              ^
    1 error
     
    C:\Program Files\Java\src\com\scjaexam\ex2_1>cd..\..\..
     
    C:\Program Files\Java\src>javac -cp .\com\scjaexam\ex2_1 iterator.java
    javac: file not found: iterator.java
    Usage: javac <options> <source files>
    use -help for a list of possible options
     
    C:\Program Files\Java\src>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Classpath override not working correctly in command prompt?

    I am wondering why it can't find the file.
    What is 'it' and what is the 'file'?

    I see that the javac program found some syntax errors in the iterator.java file
    Then you changed directory away from where the source file was and javac could not find it any more.

    The classpath is NOT for finding source files. It's for finding .class files.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Classpath override not working correctly in command prompt?

    Thank you for pointing this out.

    My textbook says that packaging is not a container for classes, like namespaces, but rather defines where they are located. So you must have a package statement in files that are to be imported?

Similar Threads

  1. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 2
    Last Post: August 30th, 2011, 09:30 AM
  2. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 1
    Last Post: August 29th, 2011, 03:05 PM
  3. Java on command prompt
    By Tanmaysinha in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 17th, 2011, 06:45 AM
  4. command prompt, acquiring input without enter?
    By kitube in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 24th, 2011, 10:14 PM
  5. [SOLVED] can't run javac directly from command prompt
    By epezhman in forum Java IDEs
    Replies: 7
    Last Post: January 12th, 2011, 07:38 PM