File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Executing jar file - Urgent  (Max Help) 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 "Executing jar file - Urgent  (Max Help)" Watch "Executing jar file - Urgent  (Max Help)" New topic

Executing jar file - Urgent (Max Help)

Amit Kr Kumar
Ranch Hand

Joined: Feb 08, 2002
Posts: 100
Hi Max and others
I am facing a very unusual problem. I have created an executable server jar file. I placed this file in the folder c:\amit.
I am able to run it using the
java -jar server.jar from the same directory where server.jar file is lying i.e. c:\amit.
However when i go to any other directory from prompt say
cd c:\xyz (REmember server.jar is still in c:\amit)
and execute java -jar server.jar it says :

Exception in thread "main" The system cannot find the file specified
at Method)
at java.util.jar.JarFile.<init>(
at java.util.jar.JarFile.<init>(
I have set the classpath as well in the prompt
using the command
set CLASSPATH=%CLASSPATH%;c:\server\server.jar;
But still not working
Important thing is that i can also start the server as
java -jar <install-dir>/server.jar no matter what is my current working directory on the command prompt
1) How to solve the above problem
2) if i run the server usung java -jar <install-dir>/server.jar and don ask the client to set any classpath, will i fulfill the exam requirement
becoz the requirement says:
How to execute the programs. You must provide exact command-line instructions. If any environmental setup is required, do not just say what needs to be done; provide instructions on how to perform the setup. For example, do not say something like "add server.jar to your classpath". You should document exactly how to add the jar file to the classpath. Note: your program must run correctly no matter what directory it is installed in.
Max Habibi
town drunk
( and author)

Joined: Jun 27, 2002
Posts: 4118
Hi Amit,
In my opinion, you don't need to provide an executable jar. Sun would certainly have said so if you did. Your readme could simply state: "Unzip this jar. Next, change directories to the whatever/starting directory", etc. After all, they will have to unzip the jar to reach your readme file.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4

Java Regular Expressions
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

set CLASSPATH=%CLASSPATH%;c:\server\server.jar;

If your jar is in c:\amit\, why is it not part of your classpath?
Amit Kr Kumar
Ranch Hand

Joined: Feb 08, 2002
Posts: 100
Sorry Eugene actually its a typo mistake
The correct classpath command i used is

So any solution ???
[ July 28, 2002: Message edited by: Amit Kr Kumar ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
The solution is to run your jar from the directory where it is located.
I agree. Here's the link:
subject: Executing jar file - Urgent (Max Help)
It's not a secret anymore!