Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

ZipException when running jar file from command file

Thread view: 
crash.test.dummy - 08 Dec 2005 22:29 GMT
A little history:
I have created a jar file, MyJar.jar
I've set the correct Manifest file so that it can run just by
double-clicking it in Windows Explorer. And it runs; no problem here.
But I need to specify VM arguments, and I can't specify VM arguments in
the manifest file (unless somebody can tell me how, I'd greatly
appreciate it).

So I created MyJar.cmd file, and specified the VM argument:

@echo off
java -jar TractorMapper.jar -Druntime.environment=TEST

both MyJar.cmd and MyJar.jar are saved in C:\sample directory.

Running MyJar.cmd is the problem.
1. If I run it by launching CMD first (Start >> All Programs >> Command
Prompt), then go the C:\sample directory then run MyJar.cmd from the
command prompt, it works ok.

2. If I run it by double-clicking MyJar.cmd from Windows Explorer, it
gives me the exception:

Exception in thread "main" java.util.zip.ZipException: The system
cannot find the file specified
       at java.util.zip.ZipFile.open(Native Method)
       at java.util.zip.ZipFile.<init>(Unknown Source)
       at java.util.jar.JarFile.<init>(Unknown Source)
       at java.util.jar.JarFile.<init>(Unknown Source)

What could be the problem?

I've tried displaying the CLASSPATH, in the hopes that in #2, the
CLASSPATH wasn't set. But on both instances, the CLASSPATH is the same.

I'm using Windows XP.

Thanks a lot for your help.
Crash.test.dummy
Oliver Wong - 08 Dec 2005 22:41 GMT
>A little history:
> I have created a jar file, MyJar.jar
[quoted text clipped - 32 lines]
>
> I'm using Windows XP.

   Did you try right clicking on the CMD file and making sure that the
"current directory" is set properly?

   - Oliver
crash.test.dummy - 08 Dec 2005 22:46 GMT
Hi Oliver,
  Are you talking about the Location: field in the General tab? If
yes, yes, it is properly set.

Thanks for your reply.

> >A little history:
> > I have created a jar file, MyJar.jar
[quoted text clipped - 37 lines]
>
>     - Oliver
Chris Smith - 09 Dec 2005 04:40 GMT
> Hi Oliver,
>    Are you talking about the Location: field in the General tab? If
> yes, yes, it is properly set.

No, Oliver was not talking about the Location field on the General tab.  
That's the directory that contains the file.  What you care about is the
"current working directory" when the command runs.

There isn't an easy way to set this.  You could do it by creating a
shortcut to the .cmd file, and then setting the property on that.

Better yet, you could specify the full path to the .jar file so that
you're not dependent on the current directory.  I'm not familiar enough
with Windows batch scripting to tell you how to do that, but it can't be
too hard... right?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

zero - 09 Dec 2005 13:53 GMT
Chris Smith <cdsmith@twu.net> wrote in news:MPG.1e02b89aa9eced75989c19
@news.altopia.net:

>> Hi Oliver,
>>    Are you talking about the Location: field in the General tab? If
[quoted text clipped - 11 lines]
> with Windows batch scripting to tell you how to do that, but it can't be
> too hard... right?

It isn't, but there's a better way.  If I understand the OP correctly, the
.cmd file is an unnecessary step.  Just create a new shortcut with target
"java -jar TractorMapper.jar -Druntime.environment=TEST"  Then right click
the new shortcut, and set the starting directory (in the shortcut tab) to
C:\sample

Signature

Beware the False Authority Syndrome

Oliver Wong - 09 Dec 2005 15:43 GMT
> Chris Smith <cdsmith@twu.net> wrote in news:MPG.1e02b89aa9eced75989c19
> @news.altopia.net:
[quoted text clipped - 20 lines]
> the new shortcut, and set the starting directory (in the shortcut tab) to
> C:\sample

   Yes, sorry, I thought the OP was working with shortcuts, not Windows
Shell scripts.

   The fields I see on the "shortcut" pane when viewing the properties of a
shortcut on Windows XP are:

Target:
Start In:
Shortcut key:
Run:
Comment:

   "Target" should contain the command you wish to run and "Start in"
should contain the directory where you want the command to run.

   - Oliver
Thomas Kellerer - 12 Dec 2005 08:51 GMT
> So I created MyJar.cmd file, and specified the VM argument:
>
> @echo off
> java -jar TractorMapper.jar -Druntime.environment=TEST

As others have pointed out, this is most probably a problem with the
current directory.

If you always store the .cmd and the .jar file in the same directory you
can use this instead:

java -jar %~dp0%TractorMapper.jar -Druntime.environment=TEST

Which will always use the TractorMapper.jar stored in the same directory
as the .cmd file

Thomas


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.