How do I execute .jar java program on Windows 7 command line?

Benny Tjia picture Benny Tjia · May 22, 2011 · Viewed 46.7k times · Source

I have been looking things up online and could not find a good answer so far. I want to execute the YUI compressor tool to obfuscate/minify my javascript file. I do have JRE installed.

It looks like the file association is fine as you can see here:

C:\directory\tempFiles>assoc .jar
    .jar=jarfile

I set up file association using ftype:

C:\directory\tempFiles>ftype jarfile
     jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*

The compressor tool is saved as a .jar file and is called "yuicompressor-2.4.6.jar"

When I try to run the .jar file, the cmd kept saying that the word 'java' is not recognized as an internal command... this is how I run it:

C:\directory\tempFiles\yuicompressor-2.4.6\build>java -jar yuicompressor-2.4.6.jar [options] [input file]

Any help would be appreciated thanks

Answer

MByD picture MByD · May 22, 2011

Add the JDK / JRE bin folder path to your PATH. See here.