Results 1 to 15 of 15
Thread: Problems with javac
- 09-05-2010, 11:32 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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)
-
- 09-06-2010, 12:48 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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
-
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.
Indeed.I really need to work this out because it would be pointless making programs which I cannot compile
- 09-06-2010, 01:53 AM #5
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.
- 09-06-2010, 10:49 AM #6
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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.
- 09-06-2010, 12:35 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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:
kind regards,Java Code:javac Hello.java
Jos
- 09-06-2010, 01:21 PM #8
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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>
- 09-06-2010, 01:32 PM #9
You have not correctly added the path to the javac.exe file to the OS's PATH variable.javac' is not recognized as an internal or external command,
The OS can not find the javac.exe file.
Open a command prompt window and enter: PATHOn my computer I have put the path to javac at the end of the list in the path textbox
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>
- 09-06-2010, 01:32 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
-
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.
- 09-06-2010, 08:56 PM #12
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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?
- 09-06-2010, 09:12 PM #13
This should work. The javac command found your source file but???C:\Program Files\Java\MyJava>javac Hello.java
Hello.java:1: error while writing Hello: Hello.class (Access is denied)
class Hello
^
1 error
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
You should NOT do any of your work in the JDK's folders.C:\Program Files\Java\jdk1.6.0_21\bin>javac Hello.java
- 09-07-2010, 08:11 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 09-07-2010, 10:17 AM #15
Member
- Join Date
- Sep 2010
- Posts
- 24
- Rep Power
- 0
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
-
Javac error
By Sotsiak in forum New To JavaReplies: 5Last Post: 06-04-2010, 08:33 AM -
javac
By PhilArmstrong in forum New To JavaReplies: 31Last Post: 11-21-2009, 03:46 PM -
javac?
By sardare in forum EclipseReplies: 1Last Post: 06-14-2008, 02:06 AM -
javac DOS
By rdunne in forum New To JavaReplies: 3Last Post: 01-01-2008, 11:49 AM -
Help with javaC
By Daniel in forum New To JavaReplies: 2Last Post: 07-04-2007, 02:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks