This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes General Computing and the fly likes Creating Windows desktop shortcut to jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Creating Windows desktop shortcut to jar" Watch "Creating Windows desktop shortcut to jar" New topic

Creating Windows desktop shortcut to jar

Colin McTaggart
Ranch Hand

Joined: Feb 01, 2011
Posts: 46
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

Joined: May 14, 2008
Posts: 5852

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.

JBoss In Action
Colin McTaggart
Ranch Hand

Joined: Feb 01, 2011
Posts: 46
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

Joined: Oct 14, 2005
Posts: 19725

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.
Have you checked out Aspose?
subject: Creating Windows desktop shortcut to jar
It's not a secret anymore!