Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

windows - Use a Java application as the Default Program for a particular file type?

I have created a text editor using Java, and have it packed in a jar file using Netbeans. Now I created a text file, with an extension of ".text". I'm on Windows 7, so using it's property window I changed the default opening program to my text editor's jar file.

Now when I double click the file with ".text" extension, windows shows a dialogbox saying "{file name} is not a valid win32 application".

Please help me out of it..

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is that a JAR file is selected as the "default application". However, JAR files are normally not executable. That is, a JAR file is not a valid Windows application. It doesn't matter if the JAR extension itself has a default application associated with it, because the "Open verb" is not used recursively in other "Open verb" definitions.

Instead,

  1. Create a batch (".BAT") file (or small EXE wrapper) that calls java (or javaw, as appropriate) and use that executable wrapper as the "Open with" program. (This will have an annoying intermediate console window if using a batch file.) Or,
  2. Modify the registry so that the "Open verb" for the extension launches the JAR through java (or javaw).

In the end, either form should look similar to: javaw -jar TheJarFile.jar "%1%". (Note that javaw is an executable, while TheJarFile.jar is not an executable.)

See java - the Java application launcher for how to use java/javaw.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...