Solved

Java executable .jar - spaces in directory path

Posted on 2001-06-23
5
2,177 Views
Last Modified: 2013-11-23

I have an executable .jar file (in Windows), that is a Swing application. When I start it by double-clicking on it, it will start only if the path it is in has no spaces in the directory path. (For example, c:\program files\myapp will not work since "program files" contains a space.

On the other hand, it will always start if it started from the command line (ie. java -jar My.jar). I know the double-click invokes javaw (instead of just java), but I don't understand why one works and the other doesn't.

I do access "user.dir" and append a subdirectory to it in my code. Could this be part of the issue? However, why does the command line invocation work?

Any thoughts?

Thanks,
Joel
0
Comment
Question by:joeltt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 60 total points
ID: 6222134
I think that is a registry problem. I don't know where it is in the registry,
perhaps you find it when you search for javaw.

if you find a string like 'javaw -jar %1' change it to 'javaw -jar "%1"'

Oh, I found something in
HKEY_CLASSES_ROOT/jarfile/Shell/Open/command
0
 
LVL 92

Expert Comment

by:objects
ID: 6222145
Sounds like you need to edit the Windows action associated with a jar file.
I think the way to do this depends on your version of Windoze but I'll go thru the Win2k procedure and you should get the idea.
Select 'Folder Options' from the Explorers Tool menu.
In the dialog pick the 'FileTypes' tab, which will present a list of file extensions/types. Scroll down till you find JAR and select it, then press the Advanced button.
This should pop up a list of Actions, and you'll probably just have one 'open'. Select 'open' and press the 'edit' button on the right. You'll then get (another) dialog showing the action name and the application used to perform the action, something like this:

C:\Program Files\JavaSoft\JRE\1.3.0_01\bin\javaw.exe -jar %1

Windows replaces the %1 with the filename of the (jar) file that u d-clicked, and if it contains spaces then the command line looks like this:

javaw.exe -jar c:\Program Files\XYZ

So it think the name of the jar is c:\Program.

To fix this simply edit the application used to perform action by putting quotes around the %1:

C:\Program Files\JavaSoft\JRE\1.3.0_01\bin\javaw.exe -jar "%1"

That should do it :)
Let me know if you have any problems.
0
 
LVL 1

Expert Comment

by:sumeetsh
ID: 6224048
hi
i have an application which uses executable jar file,and the path for the application is C:\Program Files\myBill
and I start it by double-clicking on it and it works.
I am using JDK1.2.1 and jre 1.2
its on Windows NT.
What i have done is i have add JRE to the systems PATH.





0
 
LVL 3

Author Comment

by:joeltt
ID: 6236072
You got the answer first. Thanks,J
0
 
LVL 92

Expert Comment

by:objects
ID: 6236424
Beaten my 3 minutes :-)
Good to hear you solved your problem.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question