How do you install JDK?

I have eclipse and I can test run java apps but I am not sure how to compile them. I read that I should type javac -version into my cmd.exe and see if it is recognized. It is not. So I went to sun's website and downloaded/installed JDK v6. Yet it still says 'javac' is an unrecognized command. What am I doing wrong?


UPDATE OK after reading some replies it seems like what I am trying to do is create a .jar file that can be ran on another computer (with the runtime). However I am having trouble figuring out how to do that. This might be because I am using Flex Builder(eclipse), but I added the ability to create java projects as well.


UPDATE OK I do not want to make a JAR file, I am not trying to archive it...the whole point of making a program is to send it to users so they can use the program...THAT is what I am trying to do...why is this so hard?


A JAR file can function as an executable, when you export your project as a JAR file in Eclipse (as Michael Borgwardt pointed out) you can specify what's the executable class, that meaning which one has the entry point [aka public static void main(String[] args)]

If the user installed the JRE he/she can double-click it and the application would be executed.

EDIT: For a detailed explanation of how this works, see the "How do I create executable Java program?"

To setup Eclipse to use the JDK you must follow these steps.

1.Download the JDK

First you have to download the JDK from Suns site. (Make sure you download one of them that has the JDK)

2.Install JDK

Install it and it will save some files to your hard drive. On a Windows machine this could be in c:\program files\java\jdk(version number)

3.Eclipse Preferences

Go to the Eclipse Preferences -> Java -> Installed JREs

4.Add the JDK

Click Add JRE and you only need to located the Home Directory. Click Browse... and go to where the JDK is installed on your system. The other fields will be populated for you after you locate the home directory.

5.You're done

Click Okay. If you want that JDK to be the default then put a Check Mark next to it in the Installed JRE's list.

You don't need a separate compiler, eclipse already compiles the application for you. What you probably want to do is to create an "executable" JAR file, which you can do in eclipse by selecting File->Export->Runnable JAR file.

Note, however, that the resulting JAR file is not a "real" (i.e. Windows binary) executable - it still needs a JRE installed on the target computer. There isn't really a way to create windows binaries; that's not how Java works. On the upside, it will work without recompilation on a Linux or MacOS machine (if it has a JRE installed).

javac is located in the "bin" folder of your JDK installation. In order to run it you must either use full path or add this directory to your systems search path via the Control Panel.

If you installed to c:\program files\java\jdk1.6.0 your call will have to look like this:

c:\> "c:\program files\java\jdk1.6.0\bin\javac" -version

Umm, eclipse is an IDE, it compiles things as you go. You don't need javac.

If you have Eclipse installed and you can write new java apps from within it, your compilation should work already..

Eclipse automatically builds/compiles your system when you're saving new Java files. Just try to write a new simple Hello world app, printing something to the console (just type sysout and Ctrl+Space inside Eclipse)

Eclipse automatically compiles all project in the workspace. YOu can disable this option if you like under Project->Build Automatically.

Need Your Help

Using a Single Row configuration table in SQL Server database. Bad idea?

sql database-design configuration relational-database

In developing a shopping cart application I've found that I needed to save settings and configurations based on the administrator's preferences and requirements. This information can be anything from