2

This is probably the most frequent question you get in the world, and I apologize, but I have to ask anyway. I recently downloaded the newest version of java (1.7.0_45-b18), and I recently finished making a small program for a local community of mine in Eclipse. I'd like to share it with them so anyone can run it by clicking it, but opening the jar file just hasn't seemed to work for me.

I attempted opening it with command prompt by using

java -jar StatCalc.jar

but it always tells me

'java' is not recognized as an internal or external command, operable program or batch file.

I looked up many solutions for this, the most common being to change your Path. So I went to the environment variables, and changed the path to

C:\Program Files (x86)\Java\jre7\bin\java.exe

But it still gives me the same result. Only when the directory is exactly in java, and the jar file is in the java bin folder can I run the program. I wan't any person to be able to run this.

How do I get command prompt to work and allow this program to be run by both me and other people in this small community?

user2959265
  • 21
  • 1
  • 1
  • 2
  • Did you try restarting your `cmd.exe` after appending to your `PATH`? – yamafontes Nov 06 '13 at 07:03
  • it seem that this question similar with [this question](http://stackoverflow.com/questions/7709041/javac-is-not-recognized-as-an-internal-or-external-command-operable-program-or), if yes, look up [my answer](http://stackoverflow.com/questions/7709041/javac-is-not-recognized-as-an-internal-or-external-command-operable-program-or/16562626#16562626) – Ahmad Azwar Anas Nov 06 '13 at 07:29

3 Answers3

2

The path shouldn't contain the executable itself - just the directory containing java.exe. So you want this on your path:

C:\Program Files (x86)\Java\jre7\bin

Restart your console, check that the path is correct (just run path and look at the output) and all should be well.

Note that if you're going to be developing Java code, you should probably use the JDK path instead of the JRE path. For example, my path contains c:\Program Files\Java\jdk1.7.0_17\bin. (Yes, I need to update :)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

I hope you do not have changed your PATH variable, only added (...);C:\Program Files (x86)\Java\jre7\bin\ (on UNIX systems, use a colon (:) as the separator instead) at the end. Otherwise, you will have many issues with all other Windows applications. Note that you must add the folder that contains java.exe, not the path to the executable itself.

Then, try to restart your Command-Line or even your Windows session.

Optional: You may set JAVA_HOME to specify JDK location. See this link.

Johannes H.
  • 5,875
  • 1
  • 20
  • 40
Guillaume Poussel
  • 9,572
  • 2
  • 33
  • 42
0

Here you have a tutorial of oracle for setting the path http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

C:\Program Files (x86)\Java\jre7\bin --> This would be your PATH variable.

Mikel Sanchez
  • 2,870
  • 1
  • 20
  • 28