Have the ability to set Java application as default file opener?

前端 未结 2 343
南方客
南方客 2021-01-18 09:38

I\'ve been searching for a way to have users set my program as the default to open files for awhile and found nothing. I have a program that is supposed to be universal for

相关标签:
2条回答
  • 2021-01-18 10:28

    It is answered here on stackoverflow: Use a Java application as the Default Program for a particular file type?

    Quote the answer:

    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.

    That is the case for windows. Similarly on Linux and Mac you would have to make a native application wrapper that opens a file, and passes the file's path to your java jar as a parameter and runs the jar.

    0 讨论(0)
  • 2021-01-18 10:41

    No Java does not support this. You would have to write a small app for every OS that you want to support in its native language (c++, objective c, etc.) that would simply launch your java app whenever it is opened. You can then set that app as the default program.

    0 讨论(0)
提交回复
热议问题