• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating Windows desktop shortcut to jar

 
Colin McTaggart
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
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 .
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some googling (hey, even you can google for windows command line create shortcut) and there are some Windows Scripting Host scripts available to do this.
 
Colin McTaggart
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks for your time guys.
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic