Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ZipException when running jar file from command file

1 view
Skip to first unread message

crash.test.dummy

unread,
Dec 8, 2005, 5:29:42 PM12/8/05
to
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

unread,
Dec 8, 2005, 5:41:37 PM12/8/05
to

"crash.test.dummy" <wal...@gmail.com> wrote in message
news:1134080982....@g49g2000cwa.googlegroups.com...

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

- Oliver


crash.test.dummy

unread,
Dec 8, 2005, 5:46:50 PM12/8/05
to
Hi Oliver,
Are you talking about the Location: field in the General tab? If
yes, yes, it is properly set.

Thanks for your reply.

Chris Smith

unread,
Dec 8, 2005, 11:40:20 PM12/8/05
to
crash.test.dummy <wal...@gmail.com> wrote:
> 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?

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

zero

unread,
Dec 9, 2005, 8:53:34 AM12/9/05
to
Chris Smith <cds...@twu.net> wrote in news:MPG.1e02b89aa9eced75989c19
@news.altopia.net:

> crash.test.dummy <wal...@gmail.com> wrote:
>> 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?
>

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


--
Beware the False Authority Syndrome

Oliver Wong

unread,
Dec 9, 2005, 10:43:15 AM12/9/05
to

"zero" <ze...@this.hi> wrote in message
news:Xns9727977D01...@195.130.132.70...

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

unread,
Dec 12, 2005, 3:51:44 AM12/12/05
to
On 08.12.2005 23:29 crash.test.dummy wrote:
> 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

0 new messages