Javac not working
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Javac not working

  1. #1
    Join Date
    Apr 2008
    Posts
    43

    Javac not working

    I have today installed java platform se 1.6.0_05-b13 and java development kit 6 and yet when i tried to compile a program from the command prompt window i got "javac is not recognized as an internal or external command operable program or batch file". can anyone tell me why this has happened? i have never been able to get javac to work on any of my own computers in 3 years of (limited) java programming. i have always had this problem and it's time i did something about it!

  2. #2
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Javac not working

    Where is the javac executable located? If, for instance, it's in 'C:\jdk1.6.0_03\bin' then to run it you have to type 'C:\jdk1.6.0_03\bin\javac'. If you don't want to have to type the full path, then (assuming you're using Windows), learn about the Command Prompt and the PATH variable.

  3. #3
    Join Date
    Apr 2008
    Posts
    43

    Re: Javac not working

    whenever i've done java programming at uni then to compile a program i've had to go into the directory of the .java file in a command prompt window and type "javac filename.java". this is what i'm trying to do my laptop at home but i get that message.

  4. #4
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Javac not working

    Quote Originally Posted by johntheface
    whenever i've done java programming at uni then to compile a program i've had to go into the directory of the .java file in a command prompt window and type "javac filename.java". this is what i'm trying to do my laptop at home but i get that message.
    Ooohhhh. Well, then in that case...

    Quote Originally Posted by Martin O
    learn about the Command Prompt and the PATH variable.

  5. #5
    Join Date
    Feb 2008
    Posts
    966

    Re: Javac not working

    i have never been able to get javac to work on any of my own computers in 3 years of (limited) java programming.
    Let me get this straight: you've been programming in Java for 3 years, but not ONCE have you ever compiled any of the code that you have written?

    Invest in reading up about some of the IDE's (Integrated Development Environment) such as Eclipse (my personal free favorite) or Netbeans. Also, now days if you install the SDK and JRE from Sun and install Eclipse, you shouldn't have to do anything with the classpath. At least I haven't had to mess with the classpath (for general running of Java) in a long time.

  6. #6
    Join Date
    Mar 2001
    Posts
    2,366

    Re: Javac not working

    Well all you have to do is set the PATH and the CLASSPATH environment variables in the advanced system properties tab.

    You can also do this with a batch file:
    Code:
    SET CLASSPATHPATH=C:\Program Files\jdk1.6.0_03\bin\;C:\Program Files\jdk1.6.0_03\lib\;C:\Program Files\jdk1.6.0_03\;
    SET PATH=C:\Program Files\jdk1.6.0_03\bin\;C:\Program Files\jdk1.6.0_03\lib\;c:\windows\;
    Honestly setting the CLASSPATH is not that hard, it will contain the .jar files you need to compile your program.

    The PATH variable will have javac.exe and java.exe in them. If your a dev it will definitely help to know basic stuff like that.
    Last edited by ahoodin; April 23rd, 2008 at 06:22 AM.
    ahoodin
    To keep the plot moving, that's why.

  7. #7
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Javac not working

    Quote Originally Posted by ahoodin
    Code:
    SET CLASSPATHPATH=C:\Program Files\jdk1.6.0_03\bin\;C:\Program Files\jdk1.6.0_03\lib\;C:\Program Files\jdk1.6.0_03\;
    SET PATH=C:\Program Files\jdk1.6.0_03\bin\;C:\Program Files\jdk1.6.0_03\lib\;c:\windows\;
    I don't think that classpath setting will do very much - classpath entries should either be directories that contain .class files, or the root directories of packages that contain .class files, or paths that end in the name of a jar or zip file. See Setting The Classpath. Also, I'm not sure there's much point in putting the lib directory on the path - as I understand it, Windows only looks for executables on the path (.cmd, .bat, .exe, .dll, etc).

    The inside of a computer is as dumb as hell but it goes like mad!
    R. Feynman
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  8. #8
    Join Date
    Mar 2001
    Posts
    2,366

    Re: Javac not working

    Allright...I agree about the libs. I was just showing how to set the path, not what paths all should be set, although I probably should have. It just looks like he doesn't have these environment variables set up. And fixing the problem by installing an IDE may or may not help.
    ahoodin
    To keep the plot moving, that's why.

  9. #9
    Join Date
    Oct 2006
    Posts
    74

    Resolved Re: Javac not working

    You need to setup the path variable. To do this in Windows XP you would need to go into the control panel - system - properties - environmental variables and create a new PATH.

    Set the path to the bin directory of the JDK. For example in my case it would be C:\java\bin.

    Then reset the computer. You should now be able to access Javac.

    The easiest method however would be just to install Eclipse and run your programs using this.

    You can download eclipse here :

    http://www.eclipse.org/downloads/index.php

  10. #10
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Javac not working

    Quote Originally Posted by ahoodin
    Allright...I agree about the libs. I was just showing how to set the path, not what paths all should be set, although I probably should have. It just looks like he doesn't have these environment variables set up.
    Yup, no problem - it's just that some novices tend to just copy & paste any examples you post up, and use them without much thought, so I thought it best to clarify.

    I agree that although an IDE may hide the tedious housekeeping details for everyday coding, it's important to know the basics, and that includes knowing how use the Java command-line tools.

    Furious activity is no substitute for understanding...
    H.H. Williams
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center