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?

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top