File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Problem running jar 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 "Problem running jar" Watch "Problem running jar" New topic
Author

Problem running jar

Steve Marks
Greenhorn

Joined: Feb 09, 2002
Posts: 15
Could anybody help me out with this problem?
I have created the jar files server.jar and client.jar with their manifest file from the command prompt window.
I do not have a problem with jarring them up.
The trouble that I am having is that I can`t run them in the proper manner eg: java -jar server.jar
I have to put in the full path to the jar file
eg java -jar C:\jdk1.3\server.jar
I have tried everything, adding the jars to my classpath and nothing works.
I just keep getting the same error message
java.util.ZipException system coiuld not find the specified file.
I want to be able to run the jars from any directory without putting in the full paths.
The answer to this quandary is probably very simple, something that I am overlooking.
This is the only thing holding me up uploading the assignment and it is all starting to tick me off a tad.
I never expected to get a problem from the simpler things.
Any help most appreciated.
Steve.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Show us your jar command. Oh and your manifest file
Here's mine
REM creates the jar files
jar -cvfm server.jar c:\devexam\manifest\server\manifest.mf suncertify\db\*.class suncertify\help\*.class

jar -cvfm client.jar c:\devexam\manifest\client\manifest.mf suncertify\client\*.class suncertify\db\*.class suncertify\help\*.class
REM. then remove the server files not needed

Hope that helps
Mark
[ February 18, 2002: Message edited by: Mark Spritzler ]

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Steve Marks
Greenhorn

Joined: Feb 09, 2002
Posts: 15
Thanks Mark for replying
My command was the same as how you wrote it above
except I left out the v for verbose
eg jar cmf server.jar C:\jdk1.3\suncertify\man.mf suncertify\server\*.class
I do not have a problem running it from the jar if I put in the full path to the jar.
However, I would like to be able to run it from any directory with just the command java -jar server.jar
Mathew Sam
Ranch Hand

Joined: Dec 19, 2001
Posts: 124
set the classpath
set classpath=%classpath%;c:\server\server.jar;

I assume that your server.jar is in server directory.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What about your manifest file, what does it say? This is what tells where the main class is in the jar file.
Mark
Steve Marks
Greenhorn

Joined: Feb 09, 2002
Posts: 15
Hi Mark and Matthew
Firstly inside my jar I have
Main-class: suncertify.server.DataServer
which point to the class to run.
I have added the classpath just like Matthew said
to no avail. I have tried all different ways of adding it to my calsspath. The strange thing is that I can run the program within the jar by calling java suncertify.server.DataServer from any directory, so the jar is in my classpath.
Also I can run the jar by specifying the whole path to the jar eg: java -jar C:\jdk1.3\server.jar
For some reason I cannot run it without specifying the path to the jar.
Got me stumped.
Steve.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

java -jar C:\jdk1.3\server.jar

If that works, and not
java -jar server.jar then
1. Classpath is not set to where the jar file resides.
or
2. You are not running the jar file from the directory the jar file is in.
Meaning if you have the jar in c:\devexam
run it from the c:\devexam directory.
Mark
Steve Marks
Greenhorn

Joined: Feb 09, 2002
Posts: 15
Yes Mark you are right.
If I run it in the directory which contains the jar, there is no problem.
I have tried setting the classpath to the directory that the jar resides in eg:
set classpath=c:\jdk1.3 or many other variations of this command including set classpath=C:\jdk1.3\server.jar.
My concern is that in the specs it states that you should be able to run the program in any directory,
if any environmental setup is needed you should document how to add the jar to the classpath or something along those lines.
So I an trying to get this sorted before I upload.
I suppose I could tell them to add the jar to the classpath and run it like so: java suncertify.server.DataServer which works fine.
But I was trying to sort out the former way as I think it is a better way to run the program.

Thank for your help Mark...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

you should be able to run the program in any directory?

Yes exactly. Which to me means you can put your jar file into any directory, go to that directory and run it using the java -jar server.jar. Which is what you have.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem running jar
 
Similar Threads
Unable to execute executable jar file
jar niggles
Passed With 141/155 (~91%)
Junilu, Ian, Peter and others pls help
Jar-Jar Binks and Stubs