Windows Legacy OS forum

General discussion

Set file assoc. to Java application (.jar)

by BinaryDigit09 / October 12, 2008 3:01 AM PDT

Hello!

I created an XML editor in Java and I want to set it up as the default application when I double-click an XML file. I've set up other file associations before, but for some reason the same steps aren't working when I try to associate a file extension to a .jar file (my Java app).

When I go the normal path of setting up the file association (Tools -> Folder Options -> browse to my app), Windows seems to take it fine, but when I double-click on an XML file it says "<filename.xml> is not a valid Win32 application." That seems strange to me because it's complaining about the XML file itself not being a valid app, rather than my XML Editor app that I actually pointed that file extension at.

So I tried using 'assoc' and 'ftype' in a DOS console:

C:\>assoc .xml=XMLFile
.xml=XMLFile

C:\>ftype XMLFile=C:\Program Files (x86)\Java\jre1.6.0_07\bin\java -cp C:\JavaProjects\XMLEditor\dist\XMLEditor.jar %1
XMLFile=C:\Program Files (x86)\Java\jre1.6.0_07\bin\java -cp C:\JavaProjects\XMLEditor\dist\XMLEditor.jar %1

Based on the output, it looks like there were no errors. But still, double-clicking an XML file causes the same Windows error message: "<filename.xml> is not a valid Win32 application."

Has anyone else tried to do this before and actually succeeded?

Thanks!

Discussion is locked
You are posting a reply to: Set file assoc. to Java application (.jar)
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Set file assoc. to Java application (.jar)
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
Just something I noticed.
by MarkFlax Forum moderator / October 12, 2008 7:27 PM PDT

I have no idea about this, and what you are attempting to do is a complete mystery to me, Happy

But, something I noticed about the DOS command. You will probably know that DOS doesn't handle spaces in file names and paths very well.

What would happen if you enclosed the whole path and file name in quotes?

I am probably well off the mark, and I doubt it addresses the "not a valid Win32 application" error anyway.

Mark

Collapse -
Never going to work
by Jimmy Greystone / October 13, 2008 1:37 AM PDT

It's never going to work, because JAR files are not executables. What they really are is just an uncompressed archive of a bunch of bytecompiled .class files that the Java interpreter then handles. But as far as Windows is concerned, it's NOT an executable file, and is thus no different from a Word document or an MP3 file.

What you might be able to do, is create a simple batch file wrapper around your program that accepts command line input and passes it along into the program. I'm pretty sure Java kept the argv bit from C and C++, though admittedly it's been a long time since I've done anything with Java. The batch file simply contains a single line, which is the command to launch your program, and then some placeholder variable to pass in any arguments. You can then associate XML files with this new batch file you created, because Windows will treat that as an executable file, even though it's really interpreted like your Java program.

And not to sound insulting or anything, but this sort of out of the box problem solving is something you should develop if you ever want to be a successful programmer. Simply knowing how to write code isn't going to be enough. Some day you're bound to come across a mystifying compiler error, and it will take a little creative thinking to be able to solve it.

Collapse -
Thanks
by BinaryDigit09 / October 13, 2008 6:04 AM PDT
In reply to: Never going to work

Well, I had considered bootstrapping it with a batch file or a simple executable, but I didn't want to hack it like that if Windows inherently supports what I'm trying to do and I just didn't know how. But apparently it doesn't, so thanks for your help.

Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

CNET FORUMS TOP DISCUSSION

Help, my PC with Windows 10 won't shut down properly

Since upgrading to Windows 10 my computer won't shut down properly. I use the menu button shutdown and the screen goes blank, but the system does not fully shut down. The only way to get it to shut down is to hold the physical power button down till it shuts down. Any suggestions?