set jar as default program for a file

做~自己de王妃 提交于 2019-12-12 01:15:47

问题


I want to open a specific file-format with my own jar file. That means: I want to double-click the test.bo2 file and that should open my java program and send the path of that file (maybe as command-line argument). Is something like that possible?

At the moment I guess a .jar file is not a program, so is there a workaround to run a java file from a .exe or something like that? Any suggestions?

And, to go a step further, how can I automatically set this on the first startup?


回答1:


As you are talking about ".exe" I assume you are using Windows.

You can register a new extension and the corresponding program by using ftype and assoc:

Open a commandline window, and type the following:

  1. Register the new extension:

    assoc .bo2=GenaeDocument

  2. Associate the new type with a program:

    ftype GenaeDocument=javaw.exe -jar \path\to\your\program.jar "%1"

You will obviously need to adjust the path to your jar file. This also assumes javaw.exe can be found on the path. If that is not the case, just use the full path to javaw.exe.

After this, a doubleclick on a .bo2 file should start your application. I assumed you are using a Swing (GUI) application, therefor the ftype is using javaw.exe. If your application is a console program instead, you should use java.exe

(Note this can be done somehow through the ConrolPanel/Explorer as well, but I find it quicker and easier using the commandline)



来源:https://stackoverflow.com/questions/13788132/set-jar-as-default-program-for-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!