[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Java executable .jar - spaces in directory path

Posted on 2001-06-23
5
Medium Priority
?
2,194 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 240 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

650 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