wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes JAVAC not found ??? I cant compile - help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVAC not found ??? I cant compile - help" Watch "JAVAC not found ??? I cant compile - help" New topic
Author

JAVAC not found ??? I cant compile - help

Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
im just learning java and i got a compiler and everything set up and im ready to learn java from this book i have

the compiler tells me it cannot find JAVAC... here is a pic:


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Looking at the picture, it seems that the problem is not that javac is not found, but that .\Server\*.java is not found. Are you sure about this path ?


[My Blog]
All roads lead to JavaRanch
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
what do i change it to so i can compile the file Party.java inside that folder?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Is the Server folder inside the "java shit" folder?? And when you've set the path env variable, then why are you using the complete path to javac.exe in xtra.bat??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
dont worry, i worked it out i replaced xtra.bat with


all working now
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Why are you adding the location of your java tool or the lib directory to the classpath? You ought not to put any of your own code into the Java installation folder, and you ought not to put the Java installation folder into your classpath.
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
the thing is... i have a screwed up computer that doesnt know what javac is even though its in the environment variables and told to. and if you studied the code closely you would realise that my own data actually ends up in the folder the .java is in what is called Java Shit on my desktop... nothing is added to the install directory

it works and we leave it at this
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I hope this is just a practices code and not a homework, because naming directory as "java shit" just harm your grade if tutor is die hard Java fan


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
DONT WORRY! im just starting to learn java and this is all practice
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Try the following at the command line:

javac -version
java -version

If you get anything sensible, like a version number or "HotSpot", then you have correct access to java and javac. The screenshot you posted earlier (by the way, look at this FAQ which might let you get away without screenshots; the screenshot makes the message "wider" than my screen) suggests you are getting errors from javac, so you are actually accessing javac correctly.

If you get error messages like "javac is not recognised as a file or directory or executable program," then look at this Java™ Tutorials page. That sort of message is caused by not having your system PATH variable set. The link gives you instructions how to set the PATH; you will almost certainly want the "set permanently" option.
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
*************.... always me isnt it???

i set the ************* classpath and the path etc etc and oh look



Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
OK, i have calmed down...


javac is not recognised and im 100% sure the path and classpath are correct.

please help?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
Looking at the screenshot, both PATH and CLASSPATH look screwed up. If there really are equal signs and the words "PATH" and "CLASSPATH" inside of them, then they won't work.


Ping & DNS - my free Android networking tools app
Ryan Shaw
Greenhorn

Joined: Jun 04, 2009
Posts: 27
well can you offer a solution for me to put into my path and classpath in environment variables??? according to the java site im supposed to have % and = in there...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
For PATH, something like "C:\Windows\System 32;C:\Program Files\Java\jdk1.6.0_12\bin" would seem OK.

Equals signs are part of the "SET" command that sets the PATH, but not part of PATH itself.

I recommend not to use CLASSPATH at all. If for some reason you're set on using it, then the "bin" and "lib" directories of the JDK installation should not be part of it; they do not contain class files.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
You don't really need anything in your CLASSPATH. I can't remember how you get at your environment variables in WinVista, but it something to do with r-click "my computer" --> properties --> advanced --> environment variables. At least that's what you do on WinXP, but there is a difference with the first stage on WinVista.

If there is anything in the CLASSPATH which you haven't added yourself, add this to the beginning of the CLASSPATH

.;

and delete anything you added yourself in the last 24 hours. Some applications, eg QuickTime, set up their own CLASSPATH without the . in. The . means "current directory" and once you have got that set up, you will probably never need to change your system CLASSPATH ever.

If there is nothing in the CLASSPATH which you haven't added yourself, delete the entire CLASSPATH.

And watch for my next post.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
The Sun Java Tutorial is also helpful; check out the ""Hello World!" for Microsoft Windows" and "Common Problems (and Their Solutions)" pages in http://java.sun.com/docs/books/tutorial/getStarted/index.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
On the same window as setting your CLASSPATH, you will find the PATH. This is the one you really do have to set. From the messages you got earlier, you appear to be using the JRE version of "java" which means you can run any Java program, but can't compile anything. The "javac is not recognised" error is typical of what you get if you don't set the system PATH. You can set "user PATH" or "system PATH"; you might as well set "system PATH" then everyboyd using that PC will have access to the JDK. Ulf has just given you an example of what to set.

Also, delete any references to old versions of Java from your PATH.

A PATH entry for Java begins with the Drive letter, usually C, and ends with bin.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
And why are you using batch files or the -d option, when you are just beginning? I hope your book doesn't recommend them, at least not until you get at least half-way through the book. At this stage you want to keep things as simple as possible.

Ulf has told you where to find the "Hello World" examples in the Java™ Tutorials, so what you do is
  • Open a command line
  • navigate to your Java directory with the cd command. You might need "" round the name of the directory if it contains whitespace.
  • Edit a little tiny Java™ file, eg the HelloWorld.java file.
  • Don't write any package declarations in your .java files at this stage
  • Avoid using NotePad; download NotePad++ or NotePad2 which are much better editors for programming.
  • Save that .java file in the same directory
  • "Compile" the .java file with the following instruction:
  • javac HelloWorld.java
  • Execute it with the following command:
  • java HelloWorld
  • Note when you write the extension and when you don't. Note the instructions are mostly case-sensitive.
  • Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38045
        
      22
    I have to go, shall not be available for several hours. Have you got it to work yet?
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    i havent started my book and it doesnt have any "HELLO WORLD" rubbish...


    i got my compiler from a friend as no one on this community would help me...

    the compiler seems to compile everything in the folder...

    ???

    a very confused person here

    ahhhhhh the idea of me signing up here was to get help for getting batch files that will compile my .java and to fix the stupid path and classpath


    AND I HAVE MANAGED TO FIX MY PATH AND CLASS PATH

    all i need now is instructions on how to open and compile with command prompt
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    I recommend to forget about batch files for the moment. Try to get it to work reliably from the command line first. Which commands are you using now to do that, and what are the results?
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    i dont know what command lines to use for what and the help doesnt make any sense
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    I think we could sort that out quickly if you told us, precisely, how you are trying to compile - the commands you enter, the response you get, etc.

    Anything with a space in it most likely needs to be contained in double quotes, lest it gets misinterpreted. If you're not entirely comfortable with the command line, it would be easier to use a directory name that doesn't contain spaces.
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    Ulf Dittmer wrote:I think we could sort that out quickly if you told us, precisely, how you are trying to compile - the commands you enter, the response you get, etc.

    Anything with a space in it most likely needs to be contained in double quotes, lest it gets misinterpreted. If you're not entirely comfortable with the command line, it would be easier to use a directory name that doesn't contain spaces.


    yeh i took the space out now... what command do you use to compile and what command do i use to run?


    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    First of all, instead of starting out in the C:\Windows\System32 directory, you need to change to the directory where your source resides. Something like "cd C:\Users\Ryan\Desktop\whatever" should do the trick.

    Then you need to specify which files to compile. You can either compile single files ("javac MyFile.java") or use a wildcard to compile all files ("javac *.java").

    Finally, to run the code, use "java MyFile" or "java -classpath . MyFile".

    This is all explained in detail in the Sun Java Tutorial which I linked to earlier.
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    im running command prompt from my start menu... what do you mean by change the directory?
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    I mean to type in "cd C:\Users\Ryan\Desktop\whatever" after opening the command prompt, and then to hit the return key.
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    i get this when trying to run the file Party and i have compiled it


    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    Do you have a file called "party.class" in that directory? If so, you can run it using "java party" or "java -classpath . party" (previous posts of mine as well as Campbell actually mention doing exactly that).

    The "java" command does not take a file name as argument, it takes a class name.

    I really think a thorough reading of the Tutorial (or whatever introductory book you're using) would be beneficial at this point.
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    well this is my results i think something is seriously wrong


    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41141
        
      45
    In programming you need to pay attention to detail. There's a space character between the "." and "party".
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    Ulf Dittmer wrote:In programming you need to pay attention to detail. There's a space character between the "." and "party".


    you sure?
    i cant see the space?? check again...
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11168
        
      16

    There is a space between the dot and the word party. you can always cut'n'paste it into something like notepad if you want to confirm it's really there.


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    its in my notepad but still no space... what are you guys on??



    [Thumbnail for Untitled.jpg]

    Garrett Rowe
    Ranch Hand

    Joined: Jan 17, 2006
    Posts: 1296
    That's the problem. There is a space in Ulf and Campbell's example, but there is no space in your command. The command should look like this:

    java -classpath . party

    Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    Garrett Rowe wrote:That's the problem. There is a space in Ulf and Campbell's example, but there is no space in your command. The command should look like this:

    java -classpath . party


    ok... whats wrong this time... i have the space lol


    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19655
        
      18

    The class is found but there is no "public static void main(String[] args)" method.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Ryan Shaw
    Greenhorn

    Joined: Jun 04, 2009
    Posts: 27
    but i did just what the book told me to do?

    the book cant possibly be wrong!



    [Thumbnail for Untitled.jpg]

    Garrett Rowe
    Ranch Hand

    Joined: Jan 17, 2006
    Posts: 1296
    That snippet is not a complete working program.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: JAVAC not found ??? I cant compile - help
     
    Similar Threads
    java compiler in java6
    Emma Coverage report Error
    java.lang.AssertionError: {unused}. Exception using ant 1.6.5 and JDK1.5.0_10
    Unable to get make file running?
    How to suppress comiler warnings?