Results 1 to 15 of 15
  1. #1
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Problems with javac

    I am having problems in compiling my first program (the most basic of programs (the Hello World program)).

    I saved this file as Hello.java in Notepad.

    When I brought up the command window, I changed the directory to the bin file for the Java version I am using (jdk1.6.0_12).

    I then entered javac Hello.java and it came back with it not recognising Hello.java so I entered javac and followed this with the full path to Hello.java and it came back with:

    javac: invalid flag < followed by the first part of the path to Hello.java>
    Usage: javac <options> <source files>
    use -help for a list of possible options.

    I tried the help option but could not work out which option to use. The only option I tried to use was the sourcepath option but it still did not work.

    Where am I going wrong?

    P.S. The book I am using is a very basic one (Java in easy steps by Mike McGrath)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Still no luck

    I tried the tutorial and it still did not work. The tutorial states to change directory to where the uncompiled file is (Hello.java) and then follow the prompt with javac Hello.java and it came back and said it did not recognise javac. I know the reason why which was because there is no javac file within the folder where Hello.java is situated.

    I really need to work this out because it would be pointless making programs which I cannot compile

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by gkoef View Post
    I tried the tutorial and it still did not work. The tutorial states to change directory to where the uncompiled file is (Hello.java) and then follow the prompt with javac Hello.java and it came back and said it did not recognise javac. I know the reason why which was because there is no javac file within the folder where Hello.java is situated.
    You need to re-read the tutorial as this is NOT the reason for the problem but rather it's due to your not having Java in your system path. Again, the tutorial will explain this if you look again.

    I really need to work this out because it would be pointless making programs which I cannot compile
    Indeed.

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

    Default

    It would help us help you if you could copy the full contents of the command prompt screen and paste it here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    Here are the instructions for adding the path to javac to the Windows PATH variable:
    The PATH environment variable is set from the Settings | Control Panel | System panel.
    Select the Advanced tab and
    Click on the Environment variable's button.
    At the bottom in System Variables, find the PATH entry and click the Edit button
    Add the new path using ; to separate it
    Its a stupid small text field so be careful.

  6. #6
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Better Information

    When I first tried to explain my problem not much information was given, so to explain it better I will give more information.

    On my computer I have put the path to javac at the end of the list in the path textbox and seperated it in the list with a semicolon.

    The full path to javac is C:\Program Files\Java\jdk1.6.0_21\bin
    The full path to Hello.java is C:\Program Files\Java\MyJava

    I tried a couple of ways in the Windows command window to compile Hello.java and they did not work as shown below:

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Greg>cd C:\Program Files\Java\jdk1.6.0_21\bin

    C:\Program Files\Java\jdk1.6.0_21\bin>javac Hello.java
    javac: file not found: Hello.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Program Files\Java\jdk1.6.0_21\bin>javac -help
    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
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files and annotati
    on processors
    -cp <path> Specify where to find user class files and annotati
    on processors
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -proc:{none,only} Control whether annotation processing and/or compil
    ation is done.
    -processor <class1>[,<class2>,<class3>...]Names of the annotation processors t
    o run; bypasses default discovery process
    -processorpath <path> Specify where to find annotation processors
    -d <directory> Specify where to place generated class files
    -s <directory> Specify where to place generated source files
    -implicit:{none,class} Specify whether or not to generate class files for
    implicitly referenced files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release

    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -Akey[=value] Options to pass to annotation processors
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system


    C:\Program Files\Java\jdk1.6.0_21\bin>javac C:\Program Files\Java\MyJava\Hello.j
    ava
    javac: invalid flag: C:\Program
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Program Files\Java\jdk1.6.0_21\bin>

    I tried another idea (which did not work) which I copied the Hello.java file and pasted it into the bin folder which contained the javac.exe file. Below are the results of this attempt:

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Greg>cd C:\Program Files\Java\jdk1.6.0_21\bin

    C:\Program Files\Java\jdk1.6.0_21\bin>javac Hello.java
    Hello.java:1: error while writing Hello: Hello.class (Access is denied)
    class Hello
    ^
    1 error

    C:\Program Files\Java\jdk1.6.0_21\bin>

    I really want to learn Java, but this problem needs to be ironed out before I can carry on learning. I hope someone can help.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Your first attempt failed because your Hello.java file is not stored where your compiler (javac.exe) is stored. Your second attempt failed because there is a space character in the full path name of your Hello.java file and it confuses your command line interpreter (if breaks up the command line at the wrong positions). Your third attempt is simply a hack; don't do that.

    Set your path variable to point to where your java compiler is stored, move to where your Hello.java file is stored and simply type:

    Java Code:
    javac Hello.java
    kind regards,

    Jos

  8. #8
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Dont know if I understand what you mean

    Where you said to point the variable path to where javac.exe is stored, did you mean to add the path to the list in the textbox of system variable path, which I did (seperated from the list with a semicolon)

    Where you said to move to where Hello.java is stored, I presume you meant me to open cmd window and change directory to C:\Program Files\Java\MyJava, where Hello.java is stored.

    If I am correct (which I dont think I am) I type in javac Hello.java as you said. The result is shown below:

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Greg>cd C:\Program Files\Java\MyJava

    C:\Program Files\Java\MyJava>javac Hello.java
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Program Files\Java\MyJava>

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

    Default

    javac' is not recognized as an internal or external command,
    You have not correctly added the path to the javac.exe file to the OS's PATH variable.
    The OS can not find the javac.exe file.
    On my computer I have put the path to javac at the end of the list in the path textbox
    Open a command prompt window and enter: PATH
    That will display the OS's PATH variable. Is the path to javac.exe there?

    Here is what I get:
    C:\Temp>PATH
    PATH=C:\Program Files\PHP\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDO WS\System32\Wbem;C:\Program Files\Java\jdk1.5.0_04\bin;C:\BatchFiles;C:\Progra m Files\Support Tools\;C:\WINDOWS\system32\WindowsPowerShell\v1.0; C:\Program Files\QuickTime\QTSystem\

    C:\Temp>

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by gkoef View Post
    C:\Users\Greg>cd C:\Program Files\Java\MyJava

    C:\Program Files\Java\MyJava>javac Hello.java
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Program Files\Java\MyJava>
    Obviously your path variable does not contain the directory where your javac.exe is stored. Capitalization and exact spelling counts ... basically if your javac.exe is stored in a directory path X, add X to your path variable.

    kind regards,

    Jos

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I may have missed it in the posts above, but have you changed your Windows system's path yet? Have you checked that the new system path is correct? You can get the system path by simply typing path on the command line. If you have any question about it, show us the out put from that command.

    Luck!

    EDIT: Dang I'm slow today! And I'm still waiting for that robot to bring me my beer. Has anyone seen where it went?
    Last edited by Fubarable; 09-06-2010 at 01:39 PM.

  12. #12
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Still having problems

    I checked if the path to javac.exe was present by typing path in command window and it was (sort of ) I forgot to type in the _21 part of the jdk1.6.0_21 folder, so I edited it. I tried to compile Hello.java again and it still did not work.

    I first tried changing directory to the folder containing Hello.java and the result is shown below. Something different happened here, it seemed to do nothing for about a second and then the error came up.

    The second attempt was carried out by changing directory to folder where Javac is contained and the usual result came up which is also shown below.

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Greg>cd C:\Program Files\Java\MyJava

    C:\Program Files\Java\MyJava>javac Hello.java
    Hello.java:1: error while writing Hello: Hello.class (Access is denied)
    class Hello
    ^
    1 error

    C:\Program Files\Java\MyJava>cd C:\Program Files\Java\jdk1.6.0_21\bin

    C:\Program Files\Java\jdk1.6.0_21\bin>javac Hello.java
    javac: file not found: Hello.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    C:\Program Files\Java\jdk1.6.0_21\bin>

    I am thinking that the problem may be with the Hello.java code so I have included the code below.

    class Hello
    {
    public static void main( String[] args )
    {
    System.out.println( "Hello World!" );
    }
    }

    Can anyone help in this problem?

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

    Default

    C:\Program Files\Java\MyJava>javac Hello.java
    Hello.java:1: error while writing Hello: Hello.class (Access is denied)
    class Hello
    ^
    1 error
    This should work. The javac command found your source file but???
    Why are you getting an Access denied message from the compiler?

    I just tried an experiment. I changed the properties of an existing .class file to be R/O. Here's what I get when trying to compile:
    ReverseAsString.java:14: error while writing ReverseAsString: ReverseAsString.class (Access is denied)
    public class ReverseAsString {
    ^
    1 error


    C:\Program Files\Java\jdk1.6.0_21\bin>javac Hello.java
    You should NOT do any of your work in the JDK's folders.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by gkoef View Post
    Can anyone help in this problem?
    Fix one thing first: fix your path value so that you can type "javac" no matter the value of your current directory. If you have fixed that try to compile your Hello.java file by moving to the directory where your file is stored and type "javac Hello.java".

    kind regards,

    Jos

  15. #15
    gkoef is offline Member
    Join Date
    Sep 2010
    Posts
    24
    Rep Power
    0

    Default Sussed it.

    Ive sussed it. I had two copies of the source code, One in MyJava folder within Java folder. The latter folder also contained the Java language folder (jdk1.6.0_21).

    The other source code is now in another folder outside Program Files. I used this source code and it compiled fine.

    Thanks for the help everyone, I am in no doubt that other problems WILL crop up and you will be able to give me the best advice.

Similar Threads

  1. Javac error
    By Sotsiak in forum New To Java
    Replies: 5
    Last Post: 06-04-2010, 08:33 AM
  2. javac
    By PhilArmstrong in forum New To Java
    Replies: 31
    Last Post: 11-21-2009, 03:46 PM
  3. javac?
    By sardare in forum Eclipse
    Replies: 1
    Last Post: 06-14-2008, 02:06 AM
  4. javac DOS
    By rdunne in forum New To Java
    Replies: 3
    Last Post: 01-01-2008, 11:49 AM
  5. Help with javaC
    By Daniel in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 02:44 PM

Posting Permissions

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