• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling though Command Prompt  RSS feed

 
Mohamed Said
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi am trying to compile using command prompt but this is the message i get when i type( javac HelloWorld.java)
javac:file not found:HelloWorld.java
Usage:javac<options> <source files>
use -help for a list of possible outcomes

My .java files are in C:\Kenya then i input (javac C:\Kenya \Helloworld.java but i don't get any output.
My path looks this way:
%SystemRoot%\System32\Wbem
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
C:\Program Files\Java\jdk8\bin
C:\Program Files\Java\jre8\bin

Help find a solution please
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I presume you are running a Windows® box?
It is probably a bad idea to create a folder at the root level of your C drive. It is probably better to create it in your User namespace. I suggest you write this as the first thing after opening the command line:-You won't need to use the first line again, but each time you open the command line use the second line:-
cd Kenya

That is a strange name for a Java® folder; I would have used something like Java or JavaWork myself. I would suggest you move your hello world .java file into that folder, maybe using Windows Explorer, and verify its existence with the dir instruction.

There are three likely causes for that error message:-
  • 1: There is no hello world .java file in that location.
  • 2: The file is there, but you have made a tiny spelling error in its name after javac
  • 3: The javac tool is somehow obstructed from finding the file.
  • There is something wrong about the path to the hello world file you quoted. Does it have a space in? If it has a space in, you would have to wrap the instruction in "quote marks" at the command line. What do you mean about not getting any output? The javac tool doesn't produce any output, only error messages. Successful compilation is shown by no output.
    If that doesn't help, please verify the existence and correct spelling of the file.
    If that doesn't help, try the following instruction:-
    echo %CLASSPATH%
    you should not see a CLASSPATH at all. Many people are given instructions about setting a CLASSPATH for Java®, but that is a mistake. If you have set the CLASSPATH yourself, delete it. If the CLASSPATH was there before you started, edit it by adding .; dot‑semicolon at its beginning. A CLASSPATH usually causes more harm than good.
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi i typed mkdir Kenya then cd Kenya and this is what followed

    C:\users\HP\Kenya >javac HelloWorld.java
    javac: file not found: HelloWorld.java
    Usage: javac <options> <source files>
    use -help for a list of possible options
    then i tried
    C:\Users\HP\Kenya>javac HelloWorld
    error: Class names, 'HelloWorld', are only accepted if annotation processing is explicitly requested
    1 error
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    i also try echo%Classpath% and this is what i got
    C:\Users\HP\Kenya>echo %CLASSPATH%
    %CLASSPATH%
     
    Henry Wong
    author
    Sheriff
    Posts: 23295
    125
    C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mohamed Said wrote:
    C:\users\HP\Kenya >javac HelloWorld.java
    javac: file not found: HelloWorld.java
    Usage: javac <options> <source files>


    Well, did you run the "dir" command and confirm that the file is there?

    Henry
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    C:\Users\HP\Kenya>dir
    Volume in drive C has no label.
    Volume Serial Number is 6646-72C8

    Directory of C:\Users\HP\Kenya

    05/20/2017  03:47 AM    <DIR>          .
    05/20/2017  03:47 AM    <DIR>          ..
                   0 File(s)              0 bytes
                   2 Dir(s)  230,959,079,424 bytes free
     
    Henry Wong
    author
    Sheriff
    Posts: 23295
    125
    C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Well, the directory is empty... There isn't a HelloWorld.java file there. How do you expect the compiler to find a file in an empty directory?

    Henry
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    If i type this in the cmd it opens for me the notepad(HelloWorld.java)
    C:\Users\HP\Kenya>C:\Kenya\HelloWorld.java
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Henry Wong wrote:
    Well, the directory is empty... There isn't a HelloWorld.java file there. How do you expect the compiler to find a file in an empty directory?

    Henry


    but the folder(Kenya) has HelloWorld.java , how is it empty?
     
    Mohamed Said
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If i type
    C:\Users\HP\Kenya>dir C:\Kenya
    Volume in drive C has no label.
    Volume Serial Number is 6646-72C8

    Directory of C:\Kenya

    05/20/2017  01:09 AM    <DIR>          .
    05/20/2017  01:09 AM    <DIR>          ..
    05/20/2017  12:58 AM               376 And.class
    05/20/2017  12:52 AM               110 And.java
    05/20/2017  01:01 AM               397 Arithmetic.class
    05/20/2017  12:59 AM               140 Arithmetic.java
    05/20/2017  01:02 AM               413 DataTypes.class
    05/20/2017  01:00 AM               105 DataTypes.java
    05/20/2017  01:04 AM               418 DataTypesB.class
    05/20/2017  01:03 AM               111 DataTypesB.java
    05/20/2017  01:05 AM               391 DataTypesC.class
    05/20/2017  01:05 AM               113 DataTypesC.java
    05/20/2017  02:49 AM               426 HelloWorld.class
    05/20/2017  12:49 AM               120 HelloWorld.java
    05/20/2017  01:07 AM               388 Modulo.class
    05/20/2017  01:06 AM               144 Modulo.java
    05/20/2017  01:08 AM               408 RelationalOperators.class
    05/20/2017  01:06 AM               122 RelationalOperators.java
    05/20/2017  01:09 AM               417 YourName.class
    05/20/2017  01:09 AM               121 YourName.java
                  18 File(s)          4,720 bytes
                   2 Dir(s)  230,947,774,464 bytes free
     
    Henry Wong
    author
    Sheriff
    Posts: 23295
    125
    C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mohamed Said wrote:
    but the folder(Kenya) has HelloWorld.java , how is it empty?


    You are telling the compiler to find the file in the "C:\users\HP\Kenya" directory. And *that* directory is empty.

    Henry
     
    Mike London
    Ranch Hand
    Posts: 1505
    11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Henry Wong wrote:
    Mohamed Said wrote:
    but the folder(Kenya) has HelloWorld.java , how is it empty?


    You are telling the compiler to find the file in the "C:\users\HP\Kenya" directory. And *that* directory is empty.

    Henry


    Right, you can "point" the javac to any directory, but that "end directory" must be a real path and, as Henry stated, the java file must exist there.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!