1

I have a Java program that I've made which opens and uses .project files. As long as I open the files from within the program everything works fine. However I want to be able to install the program and register (maybe even maintain) file association so that when the user will double click on a .project file one of two things will happen:

  1. If the program is not running, the program will launch and will have the file path (complete with name and extension) passed to it so it could open the clicked file.
  2. If the program is already running, do not open a second instance of the program but rather pass the file path (complete with name and extension) to the program so it could open it.

I've scoured the internet and found things such as: The Java™ Tutorials and Stack Overflow - inno setup file association but these answers are confusing. They talk about using external programs (is this necessary?) and don't explain properly how to accomplish file association in them or talk about Ant code while building in Netbeans (which I am using) but I don't really understand how to start Ant code, if I need to add it, add a new .xml file to the project or whatever.

I've tried manually associating my built JAR file in the Windows association list but it will not accept it. I am guessing I need it installed and/or converted somehow into an .exe.

In any case I want to distribute the program to others and so it needs to be done automatically.

I would prefer to have this work on multiple platforms but I am most concerned with this working on Windows (Windows 10).

Community
  • 1
  • 1
  • File association is the responsibility of the OS, so you can't have a 1-in-all solution. You either need to specify the association externally (as mentioned in the sources) or by attempting to change the OS properties (registry in Windows) through your application, but then there are security issues you need to deal with (the security manager). – user1803551 Feb 22 '16 at 15:35
  • Thank you for answering. Yes, how do I change these properties through my application? (and deal with these security issues you mentioned) – user3843826 Feb 22 '16 at 19:45
  • For Windows you will need to write to the registry. Look [here](http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java) and Google. – user1803551 Feb 22 '16 at 19:52
  • thanks. i will try these then. – user3843826 Feb 27 '16 at 08:05

0 Answers0