Results 1 to 13 of 13
  1. #1
    coke_in_a_can is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default Compiling/Running in Command Prompt

    Hi,

    I am trying to compile and run a java program from the command prompt, and I'm running into one problem after another. I've searched the net as well as this forum and haven't found a solution just yet.

    I have windows 7, and a program saved as "practice.java". My command prompt reads:

    C:\Users\gateway pc>

    To compile, I've typed "javac practice.java", which is saved in a folder titled "Java Files".

    When entered, I receive the error message:

    javac: file not found: practice.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    I've tried creating a classpath, and I've tried redefining the value of the path variable, but nothing seems to work. Any help would be greatly appreciated, thanks in advance.

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Java is case sensitive, are you sure you file isn't named Practice.java?
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    coke_in_a_can is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the fast reply.

    Yes, I double-checked. All characters are lowercase.

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Ah, I just skimmed through your post, just now I see you're trying to compile the file from a different folder. This doesn't work, to compile, you'll still need to navigate to the directory that contains the file, or specify the path, like this:
    Java Code:
    c:> javac c:\java\myprogs\Example.java
    The classpath just enables you to run your programs from anywhere, lets say your .class files (compiled files) are in c:\java, if you have your classpath set to that directory, you can do this:
    Java Code:
    c:> java Example
    Ever seen a dog chase its tail? Now that's an infinite loop.

  5. #5
    coke_in_a_can is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    I just tried typing:

    C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java

    so that the entire line in the command prompt reads:

    C:\Users\gateway pc> C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java

    And there was no response, no errors, no comfirmations... It didn't create a practice.class file as expected.

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by coke_in_a_can View Post
    I just tried typing:

    C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java

    so that the entire line in the command prompt reads:

    C:\Users\gateway pc> C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java

    And there was no response, no errors, no comfirmations... It didn't create a practice.class file as expected.
    It probably did. Did you look in C:\Users\gateway pc or in C:\Users\gateway pc\Desktop\Java Files?

    -Gary-

  7. #7
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Yup, if no messages are displayed, that means the compilation was succesfull.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    I don't understand how you didn't get something back from the javac command. Can you copy and paste from the command prompt window showing what you did.

    When I try a path with a space in a folder name I get this:
    C:\Documents and Settings\Owner>javac C:\Documents and Settings\Owner\test.java
    javac: invalid flag: C:\Documents
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing

  9. #9
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    I don't understand how you didn't get something back from the javac command. Can you copy and paste from the command prompt window showing what you did.

    When I try a path with a space in a folder name I get this:

    You don't get anything back when compilation is successful.

    -Gary-

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Have you tried using javac with a path containing a space?
    The OPs post shows 2 spaces in the path.
    C:\Users\gateway pc> C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java
    Last edited by Norm; 05-30-2010 at 03:13 AM.

  11. #11
    coke_in_a_can is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    I really appreciate all the responses.

    @ gcalvin & m00nchile

    I searched my entire computer for a practice.class file and didn't find anything.

    @Norm

    Aside from what I've found on the internet thus far, I'm not too familiar with paths or how to change them. I removed the space in the file name containing the practice.java file, so now it is "JavaFiles". Here's my most recent attempt:


    C:\Users\gateway pc>javac C:\Users\gateway pc\Desktop\JavaFiles\practice.java

    javac: invalid flag: C:\Users\gateway
    Usage: javac <options> <source files>
    use -help for a list of possible options

  12. #12
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Yeah, "gateway pc" still has a space in it. Why don't you just cd into the JavaFiles directory before running javac? If you really want to do it your way, you will have to quote the whole path.

    -Gary-

  13. #13
    coke_in_a_can is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by gcalvin View Post
    Yeah, "gateway pc" still has a space in it. Why don't you just cd into the JavaFiles directory before running javac? If you really want to do it your way, you will have to quote the whole path.

    -Gary-
    I figured out how to do that by trial and error last night... and it worked, haha. I appreciate all the help & suggestions, thanks.

Similar Threads

  1. running command prompt using java
    By xclaim in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 03:46 AM
  2. Replies: 6
    Last Post: 04-20-2009, 04:34 AM
  3. Running applet from command prompt
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 03-12-2009, 08:10 AM
  4. problems in running d command prompt commands
    By postaholic066 in forum Advanced Java
    Replies: 1
    Last Post: 09-10-2008, 03:47 PM
  5. Running eclipse java project on command prompt
    By hnmapara in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 08:29 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
  •