This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVAC not found ??? I cant compile - help

 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do i change it to so i can compile the file Party.java inside that folder?
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dont worry, i worked it out i replaced xtra.bat with


all working now
 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DONT WORRY! im just starting to learn java and this is all practice
 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*************.... always me isnt it???

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



 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, i have calmed down...


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

please help?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ryan Shaw
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Pie
    Posts: 47244
    52
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have to go, shall not be available for several hours. Have you got it to work yet?
     
    Ryan Shaw
    Greenhorn
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i dont know what command lines to use for what and the help doesnt make any sense
     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    im running command prompt from my start menu... what do you mean by change the directory?
     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i get this when trying to run the file Party and i have compiled it


     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    well this is my results i think something is seriously wrong


     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In programming you need to pay attention to detail. There's a space character between the "." and "party".
     
    Ryan Shaw
    Greenhorn
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 12017
    24
    Chrome Java Linux
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Ryan Shaw
    Greenhorn
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    its in my notepad but still no space... what are you guys on??
    Untitled.jpg
    no space here
    [Thumbnail for Untitled.jpg]
     
    Garrett Rowe
    Ranch Hand
    Posts: 1296
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Ryan Shaw
    Greenhorn
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 20372
    44
    Chrome Eclipse IDE Java Windows
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The class is found but there is no "public static void main(String[] args)" method.
     
    Ryan Shaw
    Greenhorn
    Posts: 27
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    but i did just what the book told me to do?

    the book cant possibly be wrong!
    Untitled.jpg
    well this is the page...
    [Thumbnail for Untitled.jpg]
     
    Garrett Rowe
    Ranch Hand
    Posts: 1296
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That snippet is not a complete working program.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic