This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Trouble using the jar command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trouble using the jar command" Watch "Trouble using the jar command" New topic
Author

Trouble using the jar command

Sonny Pondrom
Ranch Hand

Joined: Jun 05, 2001
Posts: 128
If the java command is used, I get the help data
If the java -version is used, I get the version info
If the jar command is used, I get unknown command.
Why is that?
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
I'm running XP, and I get the same thing. If I include the entire path for jar, then I get the help info. Odd.




Perhaps a Microsoft "feature" for discouraging Java developers? (Not that they'd do such a thing, mind you!)


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Luis F Garcia
Greenhorn

Joined: Oct 20, 2004
Posts: 6
Hi there, Jeff and Sonny !!

I rarely use XP, but I have the PATH and CLASSPATH environment variables set something like this:

PATH=C:\windows\system32;c:\j2sdk1.4.2_05\bin
CLASSPATH=C:\j2sdk1.4.2_05\jre\lib\rt.jar:.

You could do this for every DOS terminal you open by setting them in the System Properties->Advanced Options->Environment Variables.

Hope this helps.

Regards
Luis F
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Hi, Luis -

Actually, I already have my path set. I confirmed that by running the "java" and "javac" commands, which are in the same directory as the "jar" command. If the path were not set, the first two commands would not run.

Usually I run all my command line stuff from batch files anyway so that I have copies of my commands handy, so this is the first time I've seen this issue.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
That's truly bizarre. I'm on XP as well, and when I run java or jar from a random folder, they both work. I have the PATH set just as you do. I'm using 1.4.2_05 though, if that makes a difference.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
You have installed the JRE and not the SDK.
The JRE includes the 'java' executable; but not the 'jar' executable.


Tony Morris
Java Q&A (FAQ, Trivia)
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Hi, Tony -

I don't know who you're addressing, but in case I'm the intended recipient: I have both the SDK installed and the JRE. If I only had the JRE, I could not use the javac command.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

David: In which way should it make a difference to use j2sdk1.4.2_05 or j2sdk1.4.2_04?

Jeff: you didn't tell us of your PATH. Perhaps there is a ms-Java installed, which is found, but not your installation?

Luis:
Setting JAVA_HOME isn't a bad idea as well - though unrelated to 'jar not found'.
CLASSPATH=C:\j2sdk1.4.2_05\jre\lib\rt.jar:.

AFAIK you needn't set the classpath to rt.jar - perhaps depending on JAVA_HOME , in your case:


http://home.arcor.de/hirnstrom/bewerbung
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
No MS Java because I would get different version information with the java -version command.

Paths are properly set and working fine except for this one utility.

I agree that it looks and acts like a path problem, but everything else in that directory works. I'm not going to spend any more time on it because I do all my jar/compile/run processing through batch files which use the full pathname because I have to test under multiple or specific compilers or runtime engines.

Thanks for the help though.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Stefan Wagner:
David: In which way should it make a difference to use j2sdk1.4.2_05 or j2sdk1.4.2_04?
I'm not saying that it should make a difference -- just that it might. I've never experienced that problem, though I don't ever jar from the command line, only through Ant.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

David: In which way could it make a difference to use j2sdk1.4.2_05 or j2sdk1.4.2_04?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Stefan Wagner:
David: In which way could it make a difference to use j2sdk1.4.2_05 or j2sdk1.4.2_04?
There could have been an error when packaging 1.4.2_04: maybe they put the "jar" executable in the wrong directory (so it isn't in the path) or misnamed. Unlikely, but that would do it.

I mentioned it so that if someone for whom "jar" doesn't work has the same JDK version, they know to look at their environment before suspecting the JDK.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
JRE installations can sometimes override the MS java and javaw in your Windows directory with their own versions.
If that happens (some 1.4 versions do it, some don't I think) you'll end up being able to run java but not javac and jar without setting the path and getting the version you expect.

Set your path to include the J2SDK bin directory.


42
 
Consider Paul's rocket mass heater.
 
subject: Trouble using the jar command
 
Similar Threads
Connecting to an Oracle DB
SCJD- problem making jar - project from Andrew Monkhouse and Terry Camerlengo book
JAR from NetBeans
jar files
How do you Unzip a JAR file