This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am writing a generic installer for a bunch of small apps I have made in Java. They are all executable jar files and the installer writes them and any other required files to a default directory that varies depending on operating system. The only thing I am having trouble with is figuring out how to create a desktop shortcut to these apps. I need to create the shortcut and set its icon to a file I install with my software. Does anyone know how to go about doing this? For now I am focusing on windows only (I know it is different for every os .
I did spend a lot of time googling this problem before I posted actually. What I was searching for is a native java way to do this, in part this was so that I could get some practice using output streams as this is a weakness of mine. This would also mean I could use the same basic code for linux and mac but with a different kind of file being written. I know windows shortcuts are not going to be natively supported in a cross platform language but if you know how a file is constructed you can create it. I guess I'll just use native code if no-one knows a pure java way.
Colin McTaggart wrote:but if you know how a file is constructed you can create it.
That's exactly right. So you need to find the specifications for a Windows shortcut. I would expect to find that on Microsoft's developer site, although I have heard that Microsoft hasn't actually made those specs public. But that could be just a rumour, or out of date, or just wrong.
Or you could reverse-engineer a shortcut file which looks like one which you would like to generate. Don't know how easy that would be.