jQuery in Action, 3rd edition
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes jar niggles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "jar niggles" Watch "jar niggles" New topic

jar niggles

Steve Marks

Joined: Feb 09, 2002
Posts: 15
After I jarred up my client and server in jar files, I found that I could not run them in any directory just using eg: java -jar server.jar
So I did some experiments with a simpler class.
I created a simple hello world program and put it in a jar file in a package hierarchy sun/hi/Hello.class I created the jar with a manifest pointing to the file eg:
Main-Class: sun.hi.Hello I named the jar file hello.jar and stored it in C:\jdk1.3 and added the jar to my classpath.
The problem that I am having with this too is that I cannot run the program with the command java -jar hello.jar unless it is in the C:\jdk1.3 directory.
I know that the jar file is in the classpath because I can call the class directly from any directory with the command java sun.hi.Hello
The only way I can get it to function correctly is to state the whole path to the jar eg:
java -jar C:\jdk1.3\hello.jar
What am I doing wrong? what do I have to do to run the program from any directory with just the command java -jar hello.jar like it states in the specs
I must be overlooking something very simple.
Is it a classloader thing.
I hate classpath issues!!
Todd Harney

Joined: Jan 25, 2002
Posts: 23
Can you be more elaborate about how you created the JAR file? Did you use the jar command? Or did you use Winzip?
Also, the CLASSPATH setting shouldn't matter. On my windows machine here at home, I have only modified the PATH and CLASSPATH to include my Java path information. I didn't even add anything like server.jar or client.jar to my machine. And I can run the jar file from any directory using java -jar server.jar.
Any additional input would help!
Steve Marks

Joined: Feb 09, 2002
Posts: 15
I created the jar from the command prompt window
jar cfm server.jar man.mf suncertify\server\*.class
You have only the java Path info, thats interesting, I couldd not do that on my machine
how have you entered in your classpath environment
I agree. Here's the link: http://aspose.com/file-tools
subject: jar niggles
jQuery in Action, 3rd edition