ZipException when running jar file from command file

  • Thread starter crash.test.dummy
  • Start date
C

crash.test.dummy

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
 
O

Oliver Wong

crash.test.dummy said:
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.

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

- Oliver
 
C

crash.test.dummy

Hi Oliver,
Are you talking about the Location: field in the General tab? If
yes, yes, it is properly set.

Thanks for your reply.
 
C

Chris Smith

crash.test.dummy said:
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
 
Z

zero

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
 
O

Oliver Wong

zero said:
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

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
 
T

Thomas Kellerer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top