# Solved: Adding .jar files to WIndows 7 environmental variables



## Adw3537 (Nov 5, 2006)

Hi all~

Quick question-

Our class development team will be packaging a Java program for deployment and we're looking to do so via jar files. In trying to set up jar as an environmental variable within Windows 7, we're running into issues. We've tried setting up the variable within the system and user areas (with the variable being jar and the value being (full file path)/Java/jdk1.6.0_21/bin), but trying to access the command we're still receiving the error "'jar' is not recognized....... "

Does anyone have any insight or fixes.

~thanks in advance


----------



## TheOutcaste (Aug 8, 2007)

What are you going to use the variable for? Or are you trying to setup a file association?
If you have Java installed, it should already recognize a .jar file as *Executable Jar File (.jar)*.

If you need to change it to use a different program, click *Start*, type *Set Association*, then click *Make a file type always open in a specific program*.
Scroll down the list and highlight *.jar*, then click *Change Program* and select it from the list, or browse to the program you want to open .jar files with. The default would be *Java(TM) Platform SE binary*


----------



## Adw3537 (Nov 5, 2006)

I want to create a jar file, not open one


----------



## Adw3537 (Nov 5, 2006)

FYI- doing so through the command prompt


----------



## Adw3537 (Nov 5, 2006)

And just for further clarification, when trying to create the jar file, I was in the directory of the java class files that I wanted to place into the (.jar) file. Still ended up with the error message (again this is within the command prompt). "'jar' is not recognized....".


----------



## TheOutcaste (Aug 8, 2007)

Ah, so what you need is to add the path to the jar.exe file to the *path* variable.

In the Environment Variables window, under *System variables*, highlight *PATH* and click* Edit...*
Click once in the *Variable value* field, then press the *END* key.
*Make sure you do not delete anything that is already there*.
(If you do, click *Cancel* and try again)
Type a semicolon, then the full path to the JDK folder, e.g.:

```
;C:\Program Files\Java\jdk1.6.0_21\bin
```
Click *OK* until back to the Desktop, then open your Command Prompt.


----------



## Adw3537 (Nov 5, 2006)

Man, after looking at your reply, I thought the semicolon would do the trick (the only thing I left out), but alas, setting it up as a system and/or user environmental had no effect. I went to the directory that contained the class file (after making the changes you suggested) and typed in the command: (jar cvfm JarTest.jar *.class), but unfortunately still ended up with the same "'jar' is not recognized" message


----------



## TheOutcaste (Aug 8, 2007)

In the prompt type *path* and press enter.
Copy the result and paste it here.
To copy from the Command Prompt
Right click the title bar
Point to *Edit*
Click *Select All*. This highlights everything
Press *Enter*. This copies to the clipboard.
Click in the reply window, press *CTRL+V*


----------



## Adw3537 (Nov 5, 2006)

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Watts>jar
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts>dir
Volume in drive C is OS
Volume Serial Number is 922A-7661

Directory of C:\Users\Watts

10/14/2010 10:30 AM .
10/14/2010 10:30 AM ..
10/14/2010 10:30 AM 145 .appletviewer
09/21/2010 05:56 PM 214 .bash_history
09/23/2010 01:31 PM .ssh
10/19/2010 10:59 AM .VirtualBox
08/14/2010 09:16 PM Contacts
11/03/2010 11:15 PM Desktop
10/19/2010 03:26 PM Documents
11/02/2010 02:53 PM Downloads
08/14/2010 09:16 PM Favorites
10/19/2010 03:26 PM Links
10/17/2010 04:04 PM Music
08/14/2010 09:16 PM Pictures
08/14/2010 09:16 PM Saved Games
09/09/2010 11:10 AM Searches
09/21/2010 03:04 PM ssh
09/23/2010 03:51 PM Temp
08/14/2010 09:16 PM Videos
11/02/2010 02:45 PM workspace
09/21/2010 04:58 PM 596 _viminfo
3 File(s) 955 bytes
18 Dir(s) 190,931,423,232 bytes free

C:\Users\Watts>cd workspace

C:\Users\Watts\workspace>cd JarTest

C:\Users\Watts\workspace\JarTest>dir
Volume in drive C is OS
Volume Serial Number is 922A-7661

Directory of C:\Users\Watts\workspace\JarTest

11/02/2010 03:03 PM .
11/02/2010 03:03 PM ..
11/02/2010 02:45 PM 301 .classpath
11/02/2010 02:45 PM 383 .project
11/02/2010 02:45 PM .settings
11/02/2010 02:45 PM bin
11/02/2010 03:03 PM 0 jar
11/02/2010 02:45 PM src
3 File(s) 684 bytes
5 Dir(s) 190,931,423,232 bytes free

C:\Users\Watts\workspace\JarTest>cd bin

C:\Users\Watts\workspace\JarTest\bin>dir
Volume in drive C is OS
Volume Serial Number is 922A-7661

Directory of C:\Users\Watts\workspace\JarTest\bin

11/02/2010 02:45 PM .
11/02/2010 02:45 PM ..
11/02/2010 02:51 PM 693 JarTest.class
1 File(s) 693 bytes
2 Dir(s) 190,931,423,232 bytes free

C:\Users\Watts\workspace\JarTest\bin> jar cvfm JarTest.jar *.class
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts\workspace\JarTest\bin> jar cvfm JarTest.jar *.class
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts\workspace\JarTest\bin>path
PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program File
s (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Window
s;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Progra
m Files\Dell\Dell Wireless WLAN Card;c:\Program Files (x86)\Common Files\Roxio S
hared\DLLShared\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Windows
Live\Shared

C:\Users\Watts\workspace\JarTest\bin>


----------



## TheOutcaste (Aug 8, 2007)

Are you adding the path to the *PATH* variable, not a variable named *JAR*?
It's not showing in the path variable. Did you close and re-open the Command Prompt after adding it? Any changes will not affect a Command Prompt window that is already open.


----------



## Adw3537 (Nov 5, 2006)

You tell me- I've added a PNG of the screen shot to show you how I set up the variable (and yes, I closed and restarted the command prompt).

Thanks


----------



## TheOutcaste (Aug 8, 2007)

TheOutcaste said:


> Ah, so what you need is to add the path to the jar.exe file to the *path* variable.
> 
> In the Environment Variables window, under *System variables*, highlight *PATH* and click* Edit...*


you need to edit the *PATH* variable, not the jar variable. You can delete the jar variable, it won't do anything. Scroll down to find *PATH*


----------



## Adw3537 (Nov 5, 2006)

FYI- the variable name is jar (hard to see, couldn't get it to unhighlight)


----------



## Adw3537 (Nov 5, 2006)

Alright, so I changed the path as instructed, closed and restarted the CP, navigated to the correct directory and tried to create the jar file- still no success; here is the output including the path-

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Watts>jar
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts>path
PATH=C:\Program Files\Java\jdk1.0.6_21\bin

C:\Users\Watts>dir
Volume in drive C is OS
Volume Serial Number is 922A-7661

Directory of C:\Users\Watts

10/14/2010 10:30 AM .
10/14/2010 10:30 AM ..
10/14/2010 10:30 AM 145 .appletviewer
09/21/2010 05:56 PM 214 .bash_history
09/23/2010 01:31 PM .ssh
10/19/2010 10:59 AM .VirtualBox
08/14/2010 09:16 PM Contacts
11/04/2010 01:46 AM Desktop
10/19/2010 03:26 PM Documents
11/02/2010 02:53 PM Downloads
08/14/2010 09:16 PM Favorites
10/19/2010 03:26 PM Links
10/17/2010 04:04 PM Music
08/14/2010 09:16 PM Pictures
08/14/2010 09:16 PM Saved Games
09/09/2010 11:10 AM Searches
09/21/2010 03:04 PM ssh
09/23/2010 03:51 PM Temp
08/14/2010 09:16 PM Videos
11/02/2010 02:45 PM workspace
09/21/2010 04:58 PM 596 _viminfo
3 File(s) 955 bytes
18 Dir(s) 190,929,018,880 bytes free

C:\Users\Watts>cd workspace/JarTest/bin

C:\Users\Watts\workspace\JarTest\bin> jar cvfm JarTest.jar *.class
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts\workspace\JarTest\bin>path
PATH=C:\Program Files\Java\jdk1.0.6_21\bin

C:\Users\Watts\workspace\JarTest\bin>


----------



## Adw3537 (Nov 5, 2006)

And here is the screenshot of the system variable change


----------



## TheOutcaste (Aug 8, 2007)

Uh oh, you've managed to delete everything that was in the path variable, so we need to put that back in.

Are you sure the *jar.exe* file is in *C:\Program Files\Java\jdk1.0.6_21\bin*?
Is it in *C:\Program Files (x86)\Java\jdk1.0.6_21\bin* instead?
Or someplace else?

You path statement should have this:

```
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Dell\Dell Wireless WLAN Card;c:\Program Files(x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Windows Live\Shared
```
You need to copy that entire line, and put that into the PATH variable, then add a semicolon and the path to where the *jar.exe* file is located _on your system_ to the end.

Might be easier to paste it into notepad and type the path to the jar.exe file at the end, then paste it into the PATH variable value field.


----------



## Adw3537 (Nov 5, 2006)

Alright, I've replaced the variable with what existed prior and added the path to the jar file (it was in the regular program files not the x86 PF's) but unfortunately to no avail. Here is the latest output including the path

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Watts>path
PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program File
s (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Window
s;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Progra
m Files\Dell\Dell Wireless WLAN Card;c:\Program Files (x86)\Common Files\Roxio S
hared\DLLShared\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Windows
Live\Shared;C:\Program Files\Java\jdk1.0.6_21\bin

C:\Users\Watts>jar
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts>cd workspace\JarTest\bin

C:\Users\Watts\workspace\JarTest\bin>jar cvfm JarTest.jar *.class
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Watts\workspace\JarTest\bin>path
PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program File
s (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Window
s;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Progra
m Files\Dell\Dell Wireless WLAN Card;c:\Program Files (x86)\Common Files\Roxio S
hared\DLLShared\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Windows
Live\Shared;C:\Program Files\Java\jdk1.0.6_21\bin

C:\Users\Watts\workspace\JarTest\bin>


----------



## TheOutcaste (Aug 8, 2007)

If you type *Dir "C:\Program Files\Java\jdk1.0.6_21\bin\jar.exe"* does it list the file?


----------



## Adw3537 (Nov 5, 2006)

Outcaste, thanks so much for your help- its getting late and weariness and the brandy and cokes have taken their toll- BUT the awesome news is- it works!!! Going through the last post, it wouldn't list the file- it didn't exist. But going back and starting from Program Files and working in deeper, I noticed the jdk file was actually jdk1.6.0_21 (not 1.0.6_21). Just like programming, one little flipping thing will throw everything out of kilter. Changed the environmental variable and everything works like a charm! Thanks again for your help- the team (and the entire class) will be appreciative!


----------



## TheOutcaste (Aug 8, 2007)

That's one of those things you'll check 15 times before you notice the numbers are swapped, glad you spotted it.

And you're welcome!


----------

